Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MPI how to get communicator when using several executables?

In MPI we work with multiple process that do not share anything but communicate with recv/send operations. The recv/send operations are done with respect to a communicator which can be the whole set of processors or a subset of them. The basic commands are:

call MPI_Comm_size ( MPI_COMM_WORLD, nproc, ierr )
call MPI_Comm_rank ( MPI_COMM_WORLD, myrank, ierr )

with MPI_COMM_WORLD the communicator associated to the set of all processors. One interesting feature of MPI is that we can run several executables together with the command:

mpirun -n 3 prog1 : -n 2 prog2

with 3 nodes assigned to the first executable and 2 to the second. However for practical work, one would like to have a communicator associated to prog1 or prog2. Is there a way to get thi directly without using the command MPI_COMM_SPLIT?

like image 554
Mathieu Dutour Sikiric Avatar asked Nov 19 '25 14:11

Mathieu Dutour Sikiric


1 Answers

There is no such predefined communicator specified by the standard.

The great philosopher Jagger once said “you can’t always get what you want” and your best bet here is indeed to use MPI_Comm_split() and the value of MPI_COMM_WORLD's MPI_APPNUM attribute as the color argument.

From the MPI 3.1 standard chapter 10.5.3

10.5.3 MPI_APPNUM

There is a predefined attribute MPI_APPNUM of MPI_COMM_WORLD. In Fortran, the attribute is an integer value. In C, the attribute is a pointer to an integer value. If a process was spawned with MPI_COMM_SPAWN_MULTIPLE, MPI_APPNUM is the command number that generated the current process. Numbering starts from zero. If a process was spawned with MPI_COMM_SPAWN, it will have MPI_APPNUM equal to zero. Additionally, if the process was not started by a spawn call, but by an implementation specific startup mechanism that can handle multiple process specifications, MPI_APPNUM should be set to the number of the corresponding process specification. In particular, if it is started with

mpiexec spec0 [: spec1 : spec2 : ...]

MPI_APPNUM should be set to the number of the corresponding specification.

If an application was not spawned with MPI_COMM_SPAWN or MPI_COMM_SPAWN_MULTIPLE, and MPI_APPNUM does not make sense in the context of the implementation-specific startup mechanism, MPI_APPNUM is not set.

MPI implementations may optionally provide a mechanism to override the value of MPI_APPNUM through the info argument. MPI reserves the following key for all SPAWN calls.

appnum Value contains an integer that overrides the default value for MPI_APPNUM in the child.

Rationale.

When a single application is started, it is able to figure out how many processes there are by looking at the size of MPI_COMM_WORLD. An application consisting of multiple SPMD sub-applications has no way to find out how many sub-applications there are and to which sub-application the process belongs. While there are ways to figure it out in special cases, there is no general mechanism. MPI_APPNUM provides such a general mechanism. (End of rationale.)

like image 98
Gilles Gouaillardet Avatar answered Nov 21 '25 07:11

Gilles Gouaillardet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!