Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove few tests which may never finish, and change one that used too much stack...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / relrank.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include "test.h"
4
5 /* 
6  * Test that receives are done by relative rank, and that the status value
7  * contains the relative rank
8  */
9 int main( int argc, char **argv )
10 {
11     int rank, new_world_rank, size, order, errcnt = 0, i;
12     int tmpint = 0;
13     MPI_Comm new_world;
14     MPI_Status s;
15
16     MPI_Init(&argc,&argv);
17
18     MPI_Comm_rank(MPI_COMM_WORLD,&rank);
19     MPI_Comm_size(MPI_COMM_WORLD,&size);
20
21     order = size - rank - 1;
22     MPI_Comm_split(MPI_COMM_WORLD, 0, order, &new_world);
23         
24     MPI_Comm_rank ( new_world, &new_world_rank );
25
26     /* Make sure that the split worked correctly */
27     if (new_world_rank != order) {
28         errcnt ++;
29         fprintf( stderr, "Comm split did not properly order ranks!\n" );
30     }
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); */
34     }
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) {
38             errcnt++;
39             fprintf( stderr, 
40                      "Source incorrect in recv status (%d should be %d)\n",
41                      s.MPI_SOURCE, 0 );
42         }
43         /*
44           printf("%d(%d): Recv message from: -> %d(%d) <- these 2 should equal\n", 
45           new_world_rank, rank, 0, s.MPI_SOURCE); 
46           */
47     }
48
49     MPI_Comm_free( &new_world );
50     i = errcnt;
51     MPI_Allreduce( &i, &errcnt, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
52     if (errcnt > 0) {
53         printf( "Found %d errors in the run\n", errcnt );
54     }
55     Test_Waitforall( );
56     MPI_Finalize();
57     return 0;
58 }