Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / context / icdup.c
1 #include "mpi.h"
2 #include <stdio.h>
3
4 /*
5  * intended to be run with at least 3 procs
6  */
7 int main(int argc, char ** argv)
8 {
9     MPI_Comm new_intercomm;
10     MPI_Comm new_comm;
11     int my_rank, my_size;
12     int rrank;
13     int procA, procB;
14
15     MPI_Init(&argc, &argv);
16     MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
17     MPI_Comm_size( MPI_COMM_WORLD, &my_size );
18
19     if (my_size < 3) {
20         printf( "This test requires at least 3 processes: only %d provided\n",
21                 my_size );
22         MPI_Abort( MPI_COMM_WORLD, 1 );
23     }
24 #ifdef DBG
25         printf("%d: Entering main()\n", my_rank); fflush(stdout);
26 #endif
27     /* pick one of the following two settings for procA,procB */
28
29         /* uncomment these and program will work */
30         /* procA = 0; procB = 2; */
31
32         /* uncomment these and program will hang */
33         procA = 1; procB = 2;
34     /* The SGI implementation of MPI fails this test */
35     if (my_rank == procA || my_rank == procB)
36     {
37         if (my_rank == procA)
38         {
39             rrank = procB;
40         }
41         else
42         {
43             rrank = procA;
44         }
45 #ifdef DBG
46         printf("%d: Calling MPI_Intercomm_create()\n", my_rank); fflush(stdout);
47 #endif
48         MPI_Intercomm_create(MPI_COMM_SELF, 0, 
49                             MPI_COMM_WORLD, rrank, 
50                             0, &new_intercomm);
51
52 #ifdef DBG
53         printf("%d: Calling MPI_Comm_dup()\n", my_rank); fflush(stdout);
54 #endif
55         MPI_Comm_dup(new_intercomm, &new_comm);
56
57         /* Free these new communicators */
58         MPI_Comm_free( &new_comm );
59         MPI_Comm_free( &new_intercomm );
60     }
61
62     MPI_Barrier( MPI_COMM_WORLD );
63     if (my_rank == 0) {
64         printf( " No Errors\n" );
65     }
66 #ifdef DBG
67     printf("%d: Calling MPI_Finalize()\n", my_rank); fflush(stdout);
68 #endif
69     MPI_Finalize();
70     return 0;
71 }