I have a certain Fortran program which is parallelized using MPI. For a certain application I know want to run 2 fairly (but not absolutely) identical instances of this program. These 2 concurrently running programs would have to communicate with each other during runtime.
I thought one of the easiest ways to do this would be to define a global communicator (eg. MPI_COMM_WORLD_GLOBAL) which spans all the processes. I would then proceed to redefine the usual global communicator MPI_COMM_WORLD to be the total amount of processes used by this instance of the program (note that, although I talk of multiple instances of the program, there would only be 1 real program running in this case).
I would like to keep MPI_COMM_WORLD to be the total amount of processes used for 'this' instance of the program, as to avoid changing the communicators throughout my code.
My question is therefore, is there a straightforward way of redefining MPI_COMM_WORLD in Fortran? Or is my proposed approach bad practice and should I look into other methods.
Thanks in advance.
MPI_COMM_WORLD
can be just a constant or a macro. Trying to redefine it is asking for trouble.
In my OpenMPI it is a parameter
with value 9.
You would have to make your own variable with that name which shadows that one from module mpi
or mpif.h
, e.g., by using some custom module or include file.
It shouldn't be that difficult to refactor your code to use a variable for a communicator instead of the hard-coded MPI_COMM_WORLD
using some modern text editor or IDE. With some tools it can be as simple as one global Search and Replace and declaration and definition of the constant (in a module).