6 * Test that receives are done by relative rank, and that the status value
7 * contains the relative rank
9 int main( int argc, char **argv )
11 int rank, new_world_rank, size, order, errcnt = 0, i;
16 MPI_Init(&argc,&argv);
18 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
19 MPI_Comm_size(MPI_COMM_WORLD,&size);
21 order = size - rank - 1;
22 MPI_Comm_split(MPI_COMM_WORLD, 0, order, &new_world);
24 MPI_Comm_rank ( new_world, &new_world_rank );
26 /* Make sure that the split worked correctly */
27 if (new_world_rank != order) {
29 fprintf( stderr, "Comm split did not properly order ranks!\n" );
31 if (new_world_rank==0) {
32 MPI_Send(&tmpint, 1, MPI_INT, 1, 0, new_world);
33 /* printf("%d(%d): Sent message to: %d\n", new_world_rank, rank, 1); */
35 else if (new_world_rank == 1) {
36 MPI_Recv(&tmpint, 1, MPI_INT, 0, 0, new_world,&s);
37 if (s.MPI_SOURCE != 0) {
40 "Source incorrect in recv status (%d should be %d)\n",
44 printf("%d(%d): Recv message from: -> %d(%d) <- these 2 should equal\n",
45 new_world_rank, rank, 0, s.MPI_SOURCE);
49 MPI_Comm_free( &new_world );
51 MPI_Allreduce( &i, &errcnt, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
53 printf( "Found %d errors in the run\n", errcnt );