xref: /petsc/src/sys/objects/ftn-custom/zstartf.c (revision 9895aa37ac365bac650f6bd8bf977519f7222510)
1 
2 #include <petsc-private/fortranimpl.h>
3 
4 #if defined(PETSC_HAVE_FORTRAN_CAPS)
5 #define petscinitializefortran_       PETSCINITIALIZEFORTRAN
6 #define petscsetcommonblock_          PETSCSETCOMMONBLOCK
7 #define petscsetfortranbasepointers_  PETSCSETFORTRANBASEPOINTERS
8 #define petsc_null_function_          PETSC_NULL_FUNCTION
9 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
10 #define petscinitializefortran_       petscinitializefortran
11 #define petscsetcommonblock_          petscsetcommonblock
12 #define petscsetfortranbasepointers_  petscsetfortranbasepointers
13 #define petsc_null_function_          petsc_null_function
14 #endif
15 
16 #if defined(PETSC_HAVE_FORTRAN_UNDERSCORE_UNDERSCORE)
17 #define petsc_null_function_  petsc_null_function__
18 #endif
19 
20 EXTERN_C_BEGIN
21 extern void PETSC_STDCALL petscsetcommonblock_(int*,int*);
22 EXTERN_C_END
23 
24 /*@C
25    PetscInitializeFortran - Routine that should be called soon AFTER
26    the call to PetscInitialize() if one is using a C main program
27    that calls Fortran routines that in turn call PETSc routines.
28 
29    Collective on PETSC_COMM_WORLD
30 
31    Level: beginner
32 
33    Notes:
34    PetscInitializeFortran() initializes some of the default viewers,
35    communicators, etc. for use in the Fortran if a user's main program is
36    written in C.  PetscInitializeFortran() is NOT needed if a user's main
37    program is written in Fortran; in this case, just calling
38    PetscInitialize() in the main (Fortran) program is sufficient.
39 
40 .seealso:  PetscInitialize()
41 
42 .keywords: Mixing C and Fortran, passing PETSc objects to Fortran
43 @*/
44 PetscErrorCode PetscInitializeFortran(void)
45 {
46   PetscMPIInt c1=0,c2=0;
47 
48   if (PETSC_COMM_WORLD) c1 =  MPI_Comm_c2f(PETSC_COMM_WORLD);
49   /* PETSC_COMM_SELF is defined as MPI_COMM_SELF */
50   c2 =  MPI_Comm_c2f(PETSC_COMM_SELF);
51   petscsetcommonblock_(&c1,&c2);
52   return 0;
53 }
54 
55 EXTERN_C_BEGIN
56 
57 void PETSC_STDCALL petscinitializefortran_(int *ierr)
58 {
59   *ierr = PetscInitializeFortran();
60 }
61 
62 void PETSC_STDCALL petscsetfortranbasepointers_(char *fnull_character PETSC_MIXED_LEN(len),
63                                   void *fnull_integer,void *fnull_scalar,void * fnull_double,
64                                   void *fnull_real,void *fnull_object,
65                                   void* fnull_truth,void (*fnull_function)(void) PETSC_END_LEN(len))
66 {
67   PETSC_NULL_CHARACTER_Fortran = fnull_character;
68   PETSC_NULL_INTEGER_Fortran   = fnull_integer;
69   PETSC_NULL_SCALAR_Fortran    = fnull_scalar;
70   PETSC_NULL_DOUBLE_Fortran    = fnull_double;
71   PETSC_NULL_REAL_Fortran      = fnull_real;
72   PETSC_NULL_OBJECT_Fortran    = fnull_object;
73   PETSC_NULL_BOOL_Fortran      = fnull_truth;
74   PETSC_NULL_FUNCTION_Fortran  = fnull_function;
75 }
76 
77 /*
78   A valid address for the fortran variable PETSC_NULL_FUNCTION
79 */
80 void petsc_null_function_(void)
81 {
82   return;
83 }
84 
85 EXTERN_C_END
86 
87