1ba9a049bSBarry Smith 2af0996ceSBarry Smith #include <petsc/private/fortranimpl.h> 3ba9a049bSBarry Smith 4519f805aSKarl Rupp #if defined(PETSC_HAVE_FORTRAN_CAPS) 5ba9a049bSBarry Smith #define petscinitializefortran_ PETSCINITIALIZEFORTRAN 6450d9e3dSBarry Smith #define petscsetmoduleblock_ PETSCSETMODULEBLOCK 7ba9a049bSBarry Smith #define petscsetfortranbasepointers_ PETSCSETFORTRANBASEPOINTERS 8ba9a049bSBarry Smith #define petsc_null_function_ PETSC_NULL_FUNCTION 9450d9e3dSBarry Smith #define petscsetmoduleblocknumeric_ PETSCSETMODULEBLOCKNUMERIC 105ea309f3SBarry Smith #define petscsetcomm_ PETSCSETCOMM 11ba9a049bSBarry Smith #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE) 12ba9a049bSBarry Smith #define petscinitializefortran_ petscinitializefortran 13450d9e3dSBarry Smith #define petscsetmoduleblock_ petscsetmoduleblock 14ba9a049bSBarry Smith #define petscsetfortranbasepointers_ petscsetfortranbasepointers 15ba9a049bSBarry Smith #define petsc_null_function_ petsc_null_function 16450d9e3dSBarry Smith #define petscsetmoduleblocknumeric_ petscsetmoduleblocknumeric 175ea309f3SBarry Smith #define petscsetcomm_ petscsetcomm 18ba9a049bSBarry Smith #endif 19ba9a049bSBarry Smith 20ba9a049bSBarry Smith #if defined(PETSC_HAVE_FORTRAN_UNDERSCORE_UNDERSCORE) 21ba9a049bSBarry Smith #define petsc_null_function_ petsc_null_function__ 22ba9a049bSBarry Smith #endif 23ba9a049bSBarry Smith 2419caf8f3SSatish Balay PETSC_EXTERN void petscsetmoduleblock_(); 2519caf8f3SSatish Balay PETSC_EXTERN void petscsetmoduleblockmpi_(MPI_Fint*,MPI_Fint*,MPI_Fint*); 2619caf8f3SSatish Balay PETSC_EXTERN void petscsetmoduleblocknumeric_(PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*); 2719caf8f3SSatish Balay PETSC_EXTERN void petscsetcomm_(MPI_Fint*,MPI_Fint*); 28ba9a049bSBarry Smith 29ba9a049bSBarry Smith /*@C 30ba9a049bSBarry Smith PetscInitializeFortran - Routine that should be called soon AFTER 31ba9a049bSBarry Smith the call to PetscInitialize() if one is using a C main program 32ba9a049bSBarry Smith that calls Fortran routines that in turn call PETSc routines. 33ba9a049bSBarry Smith 34ba9a049bSBarry Smith Collective on PETSC_COMM_WORLD 35ba9a049bSBarry Smith 36ba9a049bSBarry Smith Level: beginner 37ba9a049bSBarry Smith 38ba9a049bSBarry Smith Notes: 39ba9a049bSBarry Smith PetscInitializeFortran() initializes some of the default viewers, 40ba9a049bSBarry Smith communicators, etc. for use in the Fortran if a user's main program is 41ba9a049bSBarry Smith written in C. PetscInitializeFortran() is NOT needed if a user's main 42ba9a049bSBarry Smith program is written in Fortran; in this case, just calling 43ba9a049bSBarry Smith PetscInitialize() in the main (Fortran) program is sufficient. 44ba9a049bSBarry Smith 45ba9a049bSBarry Smith .seealso: PetscInitialize() 46ba9a049bSBarry Smith 47ba9a049bSBarry Smith @*/ 48ba9a049bSBarry Smith PetscErrorCode PetscInitializeFortran(void) 49ba9a049bSBarry Smith { 5051674068SBarry Smith MPI_Fint c1=0,c2=0; 51ba9a049bSBarry Smith 52a297a907SKarl Rupp if (PETSC_COMM_WORLD) c1 = MPI_Comm_c2f(PETSC_COMM_WORLD); 53ba9a049bSBarry Smith c2 = MPI_Comm_c2f(PETSC_COMM_SELF); 54450d9e3dSBarry Smith petscsetmoduleblock_(); 555ea309f3SBarry Smith petscsetcomm_(&c1,&c2); 5651674068SBarry Smith 57122e1178SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 5851674068SBarry Smith { 5951674068SBarry Smith MPI_Fint freal,fscalar,fsum; 60122e1178SBarry Smith freal = MPI_Type_c2f(MPIU_REAL); 61122e1178SBarry Smith fscalar = MPI_Type_c2f(MPIU_SCALAR); 62122e1178SBarry Smith fsum = MPI_Op_c2f(MPIU_SUM); 63450d9e3dSBarry Smith petscsetmoduleblockmpi_(&freal,&fscalar,&fsum); 6451674068SBarry Smith } 6551674068SBarry Smith #endif 66639f5a5bSBarry Smith 67639f5a5bSBarry Smith { 68639f5a5bSBarry Smith PetscReal pi = PETSC_PI; 69639f5a5bSBarry Smith PetscReal maxreal = PETSC_MAX_REAL; 70639f5a5bSBarry Smith PetscReal minreal = PETSC_MIN_REAL; 71639f5a5bSBarry Smith PetscReal eps = PETSC_MACHINE_EPSILON; 72639f5a5bSBarry Smith PetscReal seps = PETSC_SQRT_MACHINE_EPSILON; 73639f5a5bSBarry Smith PetscReal small = PETSC_SMALL; 74639f5a5bSBarry Smith PetscReal pinf = PETSC_INFINITY; 75639f5a5bSBarry Smith PetscReal pninf = PETSC_NINFINITY; 76450d9e3dSBarry Smith petscsetmoduleblocknumeric_(&pi,&maxreal,&minreal,&eps,&seps,&small,&pinf,&pninf); 77639f5a5bSBarry Smith } 78ba9a049bSBarry Smith return 0; 79ba9a049bSBarry Smith } 80ba9a049bSBarry Smith 8119caf8f3SSatish Balay PETSC_EXTERN void petscinitializefortran_(int *ierr) 82ba9a049bSBarry Smith { 83ba9a049bSBarry Smith *ierr = PetscInitializeFortran(); 84ba9a049bSBarry Smith } 85ba9a049bSBarry Smith 8619caf8f3SSatish Balay PETSC_EXTERN void petscsetfortranbasepointers_(char *fnull_character, 870298fd71SBarry Smith void *fnull_integer,void *fnull_scalar,void * fnull_double, 881b266c99SBarry Smith void *fnull_real, 89*05552d4bSJunchao Zhang void* fnull_truth,void (*fnull_function)(void),void *fnull_mpi_comm,PETSC_FORTRAN_CHARLEN_T len) 90ba9a049bSBarry Smith { 91ba9a049bSBarry Smith PETSC_NULL_CHARACTER_Fortran = fnull_character; 92ba9a049bSBarry Smith PETSC_NULL_INTEGER_Fortran = fnull_integer; 93ba9a049bSBarry Smith PETSC_NULL_SCALAR_Fortran = fnull_scalar; 94ba9a049bSBarry Smith PETSC_NULL_DOUBLE_Fortran = fnull_double; 95ba9a049bSBarry Smith PETSC_NULL_REAL_Fortran = fnull_real; 96ba9a049bSBarry Smith PETSC_NULL_BOOL_Fortran = fnull_truth; 97ba9a049bSBarry Smith PETSC_NULL_FUNCTION_Fortran = fnull_function; 98*05552d4bSJunchao Zhang PETSC_NULL_MPI_COMM_Fortran = fnull_mpi_comm; 99ba9a049bSBarry Smith } 100ba9a049bSBarry Smith 101ba9a049bSBarry Smith /* 102ba9a049bSBarry Smith A valid address for the fortran variable PETSC_NULL_FUNCTION 103ba9a049bSBarry Smith */ 1048cc058d9SJed Brown PETSC_EXTERN void petsc_null_function_(void) 105ba9a049bSBarry Smith { 106ba9a049bSBarry Smith return; 107ba9a049bSBarry Smith } 108ba9a049bSBarry Smith 109ba9a049bSBarry Smith 110