creating child process with MPI_Comm_spawn

c, mpi, openmpi, spawn

Solution

You seem to misunderstand what `MPI_Comm_spawn` does. It is a collective call and it does not spawn `n` additional processes per rank but rather it spawns a child MPI job with `n` processes, therefore adding `n` to the total number of processes. When called with `n = 2`, it spawn a child job with 2 processes and that's exactly what you observe in the output.

Problem

Can someone explain why even when I set the number of process to more than 1 only two process child are created in the code below. Each MPI_Comm_spawn can create two child process using the code below, in the code used each process created with mpirun will call MPI_Comm_spawn once and will create 2 (#define NUM_SPAWNS 2) child process, so if I call N process then childs 2*N process child must be created. But this does not happen. In the example below the number of the children must be 4 * 2 = 8. But... for example: :~$ mpirun -np 4 ./spawn_example output: I'm the parent. I'm the parent. I'm the parent. I'm the parent. I'm the spawned. I'm the spawned. The following sample code illustrates MPI_Comm_spawn.

Original source