Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc 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)
25             continue;
26
27         MPI_Comm_dup(comm, &dupcomm);
28
29         /* Check that there are separate contexts.  We do this by setting
30          * up nonblocking received on both communicators, and then
31          * sending to them.  If the contexts are different, tests on the
32          * unsatisfied communicator should indicate no available message */
33         MPI_Comm_rank(comm, &rank);
34         if (rank == 0) {
35             s1buf = 456;
36             s2buf = 17;
37             r1buf = r2buf = -1;
38             /* These are send/receives to the process with rank zero
39              * in the other group (these are intercommunicators) */
40             MPI_Irecv(&r1buf, 1, MPI_INT, 0, 0, dupcomm, &rreq[0]);
41             MPI_Irecv(&r2buf, 1, MPI_INT, 0, 0, comm, &rreq[1]);
42             MPI_Send(&s2buf, 1, MPI_INT, 0, 0, comm);
43             MPI_Waitsome(2, rreq, &count, indicies, MPI_STATUSES_IGNORE);
44             if (count != 1 || indicies[0] != 1) {
45                 /* The only valid return is that exactly one message
46                  * has been received */
47                 errs++;
48                 if (count == 1 && indicies[0] != 1) {
49                     printf("Error in context values for intercomm\n");
50                 }
51                 else if (count == 2) {
52                     printf("Error: two messages received!\n");
53                 }
54                 else {
55                     int i;
56                     printf("Error: count = %d", count);
57                     for (i = 0; i < count; i++) {
58                         printf(" indicies[%d] = %d", i, indicies[i]);
59                     }
60                     printf("\n");
61                 }
62             }
63
64             /* Make sure that we do not send the next message until
65              * the other process (rank zero in the other group)
66              * has also completed the first step */
67             MPI_Sendrecv(MPI_BOTTOM, 0, MPI_BYTE, 0, 37,
68                          MPI_BOTTOM, 0, MPI_BYTE, 0, 37, comm, 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", r1buf, s1buf);
76             }
77             if (r2buf != s2buf) {
78                 errs++;
79                 printf("Wrong value in communication on comm %d != %d\n", r2buf, s2buf);
80             }
81         }
82         /* Try to duplicate a duplicated intercomm.  (This caused problems
83          * with some MPIs) */
84         MPI_Comm_dup(dupcomm, &dupcomm2);
85         MPI_Comm_free(&dupcomm2);
86         MPI_Comm_free(&dupcomm);
87         MTestFreeComm(&comm);
88     }
89     MTest_Finalize(errs);
90     MPI_Finalize();
91     return 0;
92
93 }