<p class="MsoNormal"><span style lang="EN-US">Hello All, <br></span></p><p class="MsoNormal"><span style lang="EN-US"><br></span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
running a mpi program with 4 processes and I am spawning 4 more processes and adding
them in a new intracommunicator with mpi_intercomm_merge and having a intracommunicator
with 8 processes. I am successful until this point. </span></p>
<p class="MsoNormal"><span style lang="EN-US">And then I want
to call with these 8 processes 4 new processes and add them in a new communicator
and get 12 processes in my intracommunicator. But I couldn’t spawn the new
processes with these 8 processes</span><span style lang="EN-US">. </span></p>
<p class="MsoNormal"><span style lang="EN-US">Spawned processes and other processes are
calling mpi_comm_spawn separately. At first 4 processes are calling mpi_comm_spawn
and then first spawned processes are calling mpi_comm_spawn and I am getting
two intracommunicatiors each with 8 processes. <br></span></p>
<p class="MsoNormal"><span style lang="EN-US">How can I make mpi_comm_spawn to call the new processes with new crated intracommunicator? Is
this possible? <br></span></p><p class="MsoNormal"><br></p><p class="MsoNormal"><span style lang="EN-US">Here is my code and the output
of my program: </span></p><p class="MsoNormal"><br><span style lang="EN-US"></span></p><p class="MsoNormal"><span style lang="EN-US"><b>Code:</b><br></span></p>
<p class="MsoNormal"><span style lang="EN-US">#include
"mpi.h"</span></p>
<p class="MsoNormal"><span style lang="EN-US">#include
<stdio.h></span></p>
<p class="MsoNormal"><span style lang="EN-US">#include
<stdlib.h></span></p>
<p class="MsoNormal"><span style lang="EN-US">#include
<string.h></span></p>
<p class="MsoNormal"><span style lang="EN-US">#include
<stdint.h></span></p>
<p class="MsoNormal"><span style lang="EN-US"> </span></p>
<p class="MsoNormal"><span style lang="EN-US">#define
NUM_SPAWNS 4</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Comm comm;</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Comm parentcomm, intercomm;</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span></span>int np = NUM_SPAWNS; <span style> </span></p>
<p class="MsoNormal"><span style> </span>int errcodes[4];</p>
<p class="MsoNormal"><span style> </span><span style lang="EN-US">char argv[1]; </span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>int rank; </span></p>
<p class="MsoNormal"><span style lang="EN-US">int main(
int argc, char *argv[] )</span></p>
<p class="MsoNormal"><span style lang="EN-US">{</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Init( &argc, &argv );</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Comm_get_parent( &parentcomm );</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>int i = atoi(argv[1]);</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>if (parentcomm == MPI_COMM_NULL)</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>{</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>argv[0] = "1"; </span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Comm_spawn(
"/home/umit/Desktop/merge/./a.out", argv, np, MPI_INFO_NULL, 0,
MPI_COMM_WORLD, &intercomm, errcodes );</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Intercomm_merge( intercomm,
0, &comm );</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Comm_rank (comm, &rank);
</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>printf("I am not spawned my
rank is %d \n", rank); <span style> </span></span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>}<span style> </span></span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>else </span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>{</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Intercomm_merge( parentcomm,
1, &comm ); </span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Comm_rank (comm, &rank);
</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>printf("I am spawned at %d.
call my rank is %d \n", i, rank);</span></p>
<p class="MsoNormal"><span style lang="EN-US"> </span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>if (i==2) goto jump; ///Here
secondly spawned processes jump.<span style> </span></span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>}</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>argv[0] = "2"; </span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Comm_spawn(
"/home/umit/Desktop/merge/./a.out", argv, np, MPI_INFO_NULL, 0,
MPI_COMM_WORLD, &intercomm, errcodes );</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Intercomm_merge( intercomm, 0,
&comm );</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Comm_rank (comm, &rank); </span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>jump:<span style> </span></span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>MPI_Finalize();</span></p>
<p class="MsoNormal"><span style lang="EN-US"><span style> </span>return 0;</span></p>
<p class="MsoNormal"><span style lang="EN-US">}</span></p>
<p class="MsoNormal"><span style lang="EN-US"> </span></p>
<p class="MsoNormal"><b><span style lang="EN-US">Output is:<br></span></b></p>
<p class="MsoNormal"><span style lang="EN-US">umit@ubuntu:~/Desktop/merge$
mpirun -np 4 ./a.out 0</span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 1. call my rank is 7 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am not
spawned my rank is 3 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 1. call my rank is 5 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am not
spawned my rank is 1 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 1. call my rank is 4 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am not
spawned my rank is 2 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 1. call my rank is 6 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am not
spawned my rank is 0 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 2. call my rank is 4 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 2. call my rank is 6 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 2. call my rank is 7 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 2. call my rank is 5 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 2. call my rank is 5 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 2. call my rank is 4 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 2. call my rank is 6 </span></p>
<p class="MsoNormal"><span style lang="EN-US">I am
spawned at 2. call my rank is 7</span></p>
<p class="MsoNormal"><span style lang="EN-US"> </span></p><p class="MsoNormal"><br><span style lang="EN-US"></span></p><p class="MsoNormal"><span style lang="EN-US">Best Regards, <br></span></p><p class="MsoNormal"><span style lang="EN-US"><br>
</span></p>
<p class="MsoNormal"><span style lang="EN-US"> </span></p>
<p class="MsoNormal"><span style lang="EN-US"> </span></p>
<p class="MsoNormal"><span style lang="EN-US"> </span></p>