Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add mpich3 topo tests
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / dupic.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 int main( int argc, char *argv[] )
12 {
13     int errs = 0;
14     MPI_Comm comm, dupcomm, dupcomm2;
15     MPI_Request rreq[2];
16     int count;
17     int indicies[2];
18     int r1buf, r2buf, s1buf, s2buf;
19     int rank, isLeft;
20
21     MTest_Init( &argc, &argv );
22     
23     while (MTestGetIntercomm( &comm, &isLeft, 2 )) {
24         if (comm == MPI_COMM_NULL) continue;
25
26         MPI_Comm_dup( comm, &dupcomm );
27         
28         /* Check that there are separate contexts.  We do this by setting
29            up nonblocking received on both communicators, and then
30            sending to them.  If the contexts are different, tests on the
31            unsatisfied communicator should indicate no available message */
32         MPI_Comm_rank( comm, &rank );
33         if (rank == 0) {
34             s1buf = 456;
35             s2buf = 17;
36             r1buf = r2buf = -1;
37             /* These are send/receives to the process with rank zero 
38                in the other group (these are intercommunicators) */
39             MPI_Irecv( &r1buf, 1, MPI_INT, 0, 0, dupcomm, &rreq[0] );
40             MPI_Irecv( &r2buf, 1, MPI_INT, 0, 0, comm, &rreq[1] );
41             MPI_Send( &s2buf, 1, MPI_INT, 0, 0, comm );
42             MPI_Waitsome(2, rreq, &count, indicies, MPI_STATUSES_IGNORE);
43             if (count != 1 || indicies[0] != 1) {
44                 /* The only valid return is that exactly one message
45                    has been received */
46                 errs++;
47                 if (count == 1 && indicies[0] != 1) {
48                     printf( "Error in context values for intercomm\n" );
49                 }
50                 else if (count == 2) {
51                     printf( "Error: two messages received!\n" );
52                 }
53                 else {
54                     int i;
55                     printf( "Error: count = %d", count );
56                     for (i=0; i<count; i++) {
57                         printf( " indicies[%d] = %d", i, indicies[i] );
58                     }
59                     printf( "\n" );
60                 }
61             }
62                 
63             /* Make sure that we do not send the next message until 
64                the other process (rank zero in the other group) 
65                has also completed the first step */
66             MPI_Sendrecv( MPI_BOTTOM, 0, MPI_BYTE, 0, 37,
67                           MPI_BOTTOM, 0, MPI_BYTE, 0, 37, comm, 
68                           MPI_STATUS_IGNORE );
69
70             /* Complete the receive on dupcomm */
71             MPI_Send( &s1buf, 1, MPI_INT, 0, 0, dupcomm );
72             MPI_Wait( &rreq[0], MPI_STATUS_IGNORE );
73             if (r1buf != s1buf) {
74                 errs++;
75                 printf( "Wrong value in communication on dupcomm %d != %d\n",
76                         r1buf, s1buf );
77             }
78             if (r2buf != s2buf) {
79                 errs++;
80                 printf( "Wrong value in communication on comm %d != %d\n",
81                         r2buf, s2buf );
82             }
83         }
84         /* Try to duplicate a duplicated intercomm.  (This caused problems
85          with some MPIs) */
86         MPI_Comm_dup( dupcomm, &dupcomm2 );
87         MPI_Comm_free( &dupcomm2 );
88         MPI_Comm_free( &dupcomm );
89         MTestFreeComm( &comm );
90     }
91     MTest_Finalize( errs );
92     MPI_Finalize();
93     return 0;
94   
95 }