xref: /petsc/src/sys/objects/finit.c (revision 6d8694c4fbab79f9439f1ad13c0386ba7ee1ca4b)
109d3f17cSBarry Smith #include <petsc/private/petscimpl.h> /*I  "petscsys.h"   I*/
209d3f17cSBarry Smith 
309d3f17cSBarry Smith #if defined(PETSC_USE_FORTRAN_BINDINGS)
409d3f17cSBarry Smith   #if defined(PETSC_HAVE_FORTRAN_CAPS)
509d3f17cSBarry Smith     #define petscinitializefortran_     PETSCINITIALIZEFORTRAN
609d3f17cSBarry Smith     #define petscsetmoduleblock_        PETSCSETMODULEBLOCK
709d3f17cSBarry Smith     #define petscsetmoduleblockmpi_     PETSCSETMODULEBLOCKMPI
809d3f17cSBarry Smith     #define petscsetmoduleblocknumeric_ PETSCSETMODULEBLOCKNUMERIC
909d3f17cSBarry Smith     #define petscsetcomm_               PETSCSETCOMM
1009d3f17cSBarry Smith   #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
1109d3f17cSBarry Smith     #define petscinitializefortran_     petscinitializefortran
1209d3f17cSBarry Smith     #define petscsetmoduleblock_        petscsetmoduleblock
1309d3f17cSBarry Smith     #define petscsetmoduleblockmpi_     petscsetmoduleblockmpi
1409d3f17cSBarry Smith     #define petscsetmoduleblocknumeric_ petscsetmoduleblocknumeric
1509d3f17cSBarry Smith     #define petscsetcomm_               petscsetcomm
1609d3f17cSBarry Smith   #endif
1709d3f17cSBarry Smith 
1809d3f17cSBarry Smith PETSC_EXTERN void petscsetmoduleblock_(void);
1909d3f17cSBarry Smith PETSC_EXTERN void petscsetmoduleblockmpi_(MPI_Fint *, MPI_Fint *, MPI_Fint *, MPI_Fint *);
2009d3f17cSBarry Smith PETSC_EXTERN void petscsetmoduleblocknumeric_(PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *);
2109d3f17cSBarry Smith PETSC_EXTERN void petscsetcomm_(MPI_Fint *, MPI_Fint *);
2209d3f17cSBarry Smith #endif
2309d3f17cSBarry Smith 
2409d3f17cSBarry Smith /*@C
2509d3f17cSBarry Smith   PetscInitializeFortran - Routine that should be called soon AFTER
2609d3f17cSBarry Smith   the call to `PetscInitialize()` if one is using a C main program
2709d3f17cSBarry Smith   that calls Fortran routines that in turn call PETSc routines.
2809d3f17cSBarry Smith 
2909d3f17cSBarry Smith   Collective on `PETSC_COMM_WORLD`
3009d3f17cSBarry Smith 
3109d3f17cSBarry Smith   Level: beginner
3209d3f17cSBarry Smith 
3309d3f17cSBarry Smith   Notes:
3409d3f17cSBarry Smith   `PetscInitializeFortran()` initializes some of the default viewers,
3509d3f17cSBarry Smith   communicators, etc. for use in the Fortran if a user's main program is
3609d3f17cSBarry Smith   written in C.  `PetscInitializeFortran()` is NOT needed if a user's main
3709d3f17cSBarry Smith   program is written in Fortran; in this case, just calling
3809d3f17cSBarry Smith   `PetscInitialize()` in the main (Fortran) program is sufficient.
3909d3f17cSBarry Smith 
4009d3f17cSBarry Smith   This function exists and can be called even if PETSc has been configured
41*26a11704SBarry Smith   with `--with-fortran-bindings=0` or `--with-fc=0`. It just does nothing
4209d3f17cSBarry Smith   in that case.
4309d3f17cSBarry Smith 
4409d3f17cSBarry Smith .seealso: `PetscInitialize()`
4509d3f17cSBarry Smith @*/
PetscInitializeFortran(void)4609d3f17cSBarry Smith PetscErrorCode PetscInitializeFortran(void)
4709d3f17cSBarry Smith {
4809d3f17cSBarry Smith #if defined(PETSC_USE_FORTRAN_BINDINGS)
4909d3f17cSBarry Smith   MPI_Fint c1 = 0, c2 = 0;
5009d3f17cSBarry Smith 
5109d3f17cSBarry Smith   if (PETSC_COMM_WORLD) c1 = MPI_Comm_c2f(PETSC_COMM_WORLD);
5209d3f17cSBarry Smith   c2 = MPI_Comm_c2f(PETSC_COMM_SELF);
5309d3f17cSBarry Smith   petscsetmoduleblock_();
5409d3f17cSBarry Smith   petscsetcomm_(&c1, &c2);
5509d3f17cSBarry Smith 
5609d3f17cSBarry Smith   {
5709d3f17cSBarry Smith     MPI_Fint freal, fscalar, fsum, fint;
5809d3f17cSBarry Smith     freal   = MPI_Type_c2f(MPIU_REAL);
5909d3f17cSBarry Smith     fscalar = MPI_Type_c2f(MPIU_SCALAR);
6009d3f17cSBarry Smith     fsum    = MPI_Op_c2f(MPIU_SUM);
6109d3f17cSBarry Smith     fint    = MPI_Type_c2f(MPIU_INT);
6209d3f17cSBarry Smith     petscsetmoduleblockmpi_(&freal, &fscalar, &fsum, &fint);
6309d3f17cSBarry Smith   }
6409d3f17cSBarry Smith 
6509d3f17cSBarry Smith   {
6609d3f17cSBarry Smith     PetscReal pi      = PETSC_PI;
6709d3f17cSBarry Smith     PetscReal maxreal = PETSC_MAX_REAL;
6809d3f17cSBarry Smith     PetscReal minreal = PETSC_MIN_REAL;
6909d3f17cSBarry Smith     PetscReal eps     = PETSC_MACHINE_EPSILON;
7009d3f17cSBarry Smith     PetscReal seps    = PETSC_SQRT_MACHINE_EPSILON;
7109d3f17cSBarry Smith     PetscReal small   = PETSC_SMALL;
7209d3f17cSBarry Smith     PetscReal pinf    = PETSC_INFINITY;
7309d3f17cSBarry Smith     PetscReal pninf   = PETSC_NINFINITY;
7409d3f17cSBarry Smith     petscsetmoduleblocknumeric_(&pi, &maxreal, &minreal, &eps, &seps, &small, &pinf, &pninf);
7509d3f17cSBarry Smith   }
7609d3f17cSBarry Smith #endif
7709d3f17cSBarry Smith   return PETSC_SUCCESS;
7809d3f17cSBarry Smith }
79