Updated: I have a problem, and I don't know what it is. I have a test program with MPI_INIT and MPI_FINALIZE in its body. I have a module that contains 5 subroutines: 3 subroutines are dependent, and independent from 2 other subroutines. I want to put the MPI code in the test program into this module. I put MPI_INIT in the module where the variables are declared and before the subroutine. I obtain a series of errors with the same error message:
This statement must not appear in the specification part of a module
How does "MPI_INIT and MPI_FINALIZE should be called only once" affect Fortran program, modules, and subroutines? Where should I put MPI functions and variables if there are multiple, independent programs, each calling this module's subroutines multiple number of times?
~~~~~~~~~ I have a module that contains a series of subroutines, which contain do loops that I wish to parallelize. The subroutines are public that other programs use. Should I define MPI outside the subroutines:
module ...
call MPI_INIT
subroutine 1
... (MPI code)
subroutine 2
subroutine 3
MPI_GATHERV
call MPI_FINALIZE
module
or inside each subroutine?
module ...
subroutine 1
call MPI_INIT
... (MPI code)
MPI_GATHERV
call MPI_FINALIZE
subroutine 2
call MPI_INIT
... (MPI code)
MPI_GATHERV
call MPI_FINALIZE
subroutine 3
call MPI_INIT
... (MPI code)
MPI_GATHERV
call MPI_FINALIZE
module
I see the advantage of following the coarse grain principle for solution 1. If a program calls subroutine 1, will it also execute MPI codes outside the subroutine?