in the code below. I use MPI_Comm_excl to exclude rank 0 of MPI_COMM_WORLD
and then split the remaining ranks in "buckets" and correspond a communicator. I use Allreduce in order to sum the workersid (after excluding rank 0 and before splitting) and spread the results (And seems that works). But now I am trying to build an intercommunicator between the excluding rank 0 and the spitting "buckets".
MPI_Intercomm_create ( MPI_Comm local_comm, int local_leader,
MPI_Comm peer_comm, int remote_leader, int tag,
MPI_Comm *comm_out )
local_comm->workers_comm
local_leader->0 (not know exactly what means. Is this the starting value of the ranking in local_comm)
peer_comm-> Is this for my example MPI_COMM_WORLD (the excluding rank 0 has still this comm?)
remote leader->(same question as local)
tag-> whatever
comm_out-> new communicator
The execution holds on MPI_IntercommCode:#include "mpi.h" #include <stdio.h> int main(argc,argv) int argc; char *argv[]; { int rank,rank2,group_size,group_size2,comm_size,comm_size2,new_rank, sendbuf, recvbuf, server=0; int ranks[1],workersid, workersize; int array2, array1,array3; int color=4,mpi_errno; MPI_Comm world,workers_comm,workers,cowork_comm; MPI_Group worker_group, world_group; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &comm_size); MPI_Status status; ranks[0]=server; printf("rank= %d comm_size=%d \n",rank, comm_size); world=MPI_COMM_WORLD; MPI_Comm_group(world,&world_group); MPI_Group_excl(world_group,1,ranks,&worker_group); MPI_Comm_create(world,worker_group,&workers); if(rank!=0){ MPI_Comm_rank(workers,&workersid); MPI_Comm_size(workers,&workersize); printf("workersid= %d workersize=%d \n",workersid,workersize); array1=workersid; if ((workersid>0) && (workersid<4)){color=1;} if ((workersid>3)&& (workersid<7)){color=2;} if ((workersid>6)&& (workersid<10)){color=3;} if ((workersid>9)&& (workersid<21)){color=4;} MPI_Comm_split(workers,color,workersid,&workers_comm); MPI_Comm_rank(workers_comm,&rank2); MPI_Comm_size(workers_comm,&comm_size2); printf("size=%d size2= %d comm_size2=%d new rank= %d\n",group_size,group_size2, comm_size2,rank2); MPI_Allreduce(&array1,&array2,1,MPI_INT,MPI_SUM,workers_comm); printf("array1=%d array2= %d comm_size2=%d new rank= %d\n",array1,array2, comm_size2,rank2); /*MPI_Barrier(workers_comm);*/ MPI_Intercomm_create(workers_comm,0,world,0,99,&cowork_comm); printf("\n........\n"); /*MPI_Send(&array2,0,MPI_INT,0,9,cowork_comm);*/ } */ if(rank==0){ /*MPI_Recv(&array,1,MPI_INT,0,9,cowork_comm, &status)*/ printf("array1 = %d array2= %d\n",array1,array2); } if (rank!=0){ MPI_Comm_free(&workers_comm); MPI_Comm_free(&cowork_comm); MPI_Comm_free(&workers); MPI_Group_free(&worker_group); } MPI_Finalize(); }
mpirun -n 10 ...
with mpich1
any help welcomeCode:rank= 1 comm_size=10 rank= 2 comm_size=10 rank= 3 comm_size=10 rank= 4 comm_size=10 rank= 5 comm_size=10 rank= 6 comm_size=10 rank= 7 comm_size=10 rank= 8 comm_size=10 rank= 0 comm_size=10 rank= 9 comm_size=10 workersid= 2 workersize=9 workersid= 5 workersize=9 workersid= 7 workersize=9 array1 = 0 array2= 0 workersid= 0 workersize=9 workersid= 4 workersize=9 workersid= 6 workersize=9 workersid= 3 workersize=9 workersid= 8 workersize=9 workersid= 1 workersize=9 size=32681 size2= 4417456 comm_size2=3 new rank= 0 size=32681 size2= 4417456 comm_size2=3 new rank= 2 size=32681 size2= 4417456 comm_size2=2 new rank= 0 size=32681 size2= 4417456 comm_size2=3 new rank= 1 size=32681 size2= 4417456 comm_size2=3 new rank= 1 size=32681 size2= 4417456 comm_size2=1 new rank= 0 size=32681 size2= 4417456 comm_size2=3 new rank= 0 array1=0 array2= 0 comm_size2=1 new rank= 0 array1=2 array2= 6 comm_size2=3 new rank= 1 size=32681 size2= 4417456 comm_size2=2 new rank= 1 array1=3 array2= 6 comm_size2=3 new rank= 2 array1=8 array2= 15 comm_size2=2 new rank= 1 array1=7 array2= 15 comm_size2=2 new rank= 0 array1=1 array2= 6 comm_size2=3 new rank= 0 size=32681 size2= 4417456 comm_size2=3 new rank= 2 array1=6 array2= 15 comm_size2=3 new rank= 2 array1=5 array2= 15 comm_size2=3 new rank= 1 array1=4 array2= 15 comm_size2=3 new rank= 0