c - comm_split strange behavior? -
i have spent quite few hours trying figure out have come here help. learning mpi , problem since new don't know why weird behavior occurs. trying have 8 numbers spread across 8 processors follows. split communicator exchange elements sub communicator follows:
0 1 2 3 4 5 6 7
split
0 1 2 3 | 4 5 6 7
exchange
2 3 0 1 | 6 7 4 5
the output 4 5 6 7 0 1 2 3 output should 2 3 0 1 6 7 4 5. can on why giving me strange result?
#include <stdio.h> #include <stdlib.h> #include <mpi.h> #include <math.h> int main(argc,argv) int argc; char *argv[]; { int myid, numprocs; int color,zero_one,new_id,new_nodes; mpi_comm new_comm; mpi_init(&argc,&argv); mpi_comm_size(mpi_comm_world,&numprocs); mpi_comm_rank(mpi_comm_world,&myid); int my_num, my_received; int old_id; switch(myid){ case 0: my_num = 0; old_id = 0; break; case 1: my_num = 1; old_id = 1; break; case 2: my_num = 2; old_id = 2; break; case 3: my_num = 3; old_id = 3; break; case 4: my_num = 4; old_id = 4; break; case 5: my_num = 5; old_id = 5; break; case 6: my_num = 6; old_id = 6; break; case 7: my_num = 7; old_id = 7; break; } //here split color=myid % 2; mpi_comm_split(mpi_comm_world,color,myid,&new_comm); mpi_comm_rank( new_comm, &new_id); mpi_comm_rank( new_comm, &new_nodes); //here exchange in sub list or communicator if(new_id < 2){ mpi_send(&my_num, 1, mpi_int, 2 + new_id, 0, new_comm); mpi_recv(&my_received, 1, mpi_int, 2 + new_id, 0, new_comm, mpi_status_ignore); } else { mpi_recv(&my_received, 1, mpi_int, new_id - 2, 0, new_comm, mpi_status_ignore); mpi_send(&my_num, 1, mpi_int, new_id - 2 , 0, new_comm); } printf("old_id= %d received num= %d\n", old_id, my_received); mpi_finalize(); }
running program get:
old_id= 4 received num= 0 old_id= 5 received num= 1 old_id= 1 received num= 5 old_id= 3 received num= 7 old_id= 6 received num= 2 old_id= 7 received num= 3 old_id= 0 received num= 4 old_id= 2 received num= 6 according split, ranks collected in 1 communicator , odds in another:
old_id= 0 received num= 4 old_id= 2 received num= 6 old_id= 4 received num= 0 old_id= 6 received num= 2 and:
old_id= 1 received num= 5 old_id= 3 received num= 7 old_id= 5 received num= 1 old_id= 7 received num= 3 which looks thing asked for. either can't reproduce problem, misunderstood or nothing wrong?
Comments
Post a Comment