Actual source code: finit.c
1: #include <petsc/private/petscimpl.h>
3: #if PetscDefined(USE_FORTRAN_BINDINGS)
4: #if PetscDefined(HAVE_FORTRAN_CAPS)
5: #define petscinitializefortran_ PETSCINITIALIZEFORTRAN
6: #define petscsetmoduleblock_ PETSCSETMODULEBLOCK
7: #elif !PetscDefined(HAVE_FORTRAN_UNDERSCORE)
8: #define petscinitializefortran_ petscinitializefortran
9: #define petscsetmoduleblock_ petscsetmoduleblock
10: #endif
12: PETSC_EXTERN void petscsetmoduleblock_(void);
13: PETSC_EXTERN void petscsetmoduleblockmpi(MPI_Fint *, MPI_Fint *, MPI_Fint *, MPI_Fint *, MPI_Fint *);
14: PETSC_EXTERN void petscsetmoduleblocknumeric(PetscReal *);
15: PETSC_EXTERN void petscsetcomm(MPI_Fint *, MPI_Fint *);
16: #endif
18: /*@
19: PetscInitializeFortran - Routine that should be called soon AFTER
20: the call to `PetscInitialize()` if one is using a C main program
21: that calls Fortran routines that in turn call PETSc routines.
23: Collective on `PETSC_COMM_WORLD`
25: Level: beginner
27: Notes:
28: `PetscInitializeFortran()` initializes some of the default viewers,
29: communicators, etc. for use in the Fortran if a user's main program is
30: written in C. `PetscInitializeFortran()` is NOT needed if a user's main
31: program is written in Fortran; in this case, just calling
32: `PetscInitialize()` in the main (Fortran) program is sufficient.
34: This function exists and can be called even if PETSc has been configured
35: with `--with-fortran-bindings=0` or `--with-fc=0`. It just does nothing
36: in that case.
38: .seealso: `PetscInitialize()`
39: @*/
40: PetscErrorCode PetscInitializeFortran(void)
41: {
42: #if PetscDefined(USE_FORTRAN_BINDINGS)
43: MPI_Fint c1 = 0, c2 = 0;
45: if (PETSC_COMM_WORLD) c1 = MPI_Comm_c2f(PETSC_COMM_WORLD);
46: c2 = MPI_Comm_c2f(PETSC_COMM_SELF);
47: petscsetmoduleblock_();
48: petscsetcomm(&c1, &c2);
50: {
51: MPI_Fint freal, fscalar, fsum, fint, fcbool;
52: freal = MPI_Type_c2f(MPIU_REAL);
53: fscalar = MPI_Type_c2f(MPIU_SCALAR);
54: fsum = MPI_Op_c2f(MPIU_SUM);
55: fint = MPI_Type_c2f(MPIU_INT);
56: fcbool = MPI_Type_c2f(MPI_C_BOOL);
57: petscsetmoduleblockmpi(&freal, &fscalar, &fsum, &fint, &fcbool);
58: }
60: {
61: PetscReal small = PETSC_SMALL;
62: petscsetmoduleblocknumeric(&small);
63: }
64: #endif
65: return PETSC_SUCCESS;
66: }