Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the compilation of MPICH3 tests with the absolute paranoid flags (enable_maintainer)
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / icsend.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 /*
12 static char MTEST_Descrip[] = "Simple test of intercommunicator send and receive";
13 */
14
15 int main(int argc, char *argv[])
16 {
17     int errs = 0;
18     int leftGroup, buf, rank, remote_size, i;
19     MPI_Comm comm;
20     MPI_Status status;
21
22     MTest_Init(&argc, &argv);
23
24     while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
25         if (comm == MPI_COMM_NULL)
26             continue;
27
28         if (leftGroup) {
29             MPI_Comm_rank(comm, &rank);
30             buf = rank;
31             MPI_Send(&buf, 1, MPI_INT, 0, 0, comm);
32         }
33         else {
34             MPI_Comm_remote_size(comm, &remote_size);
35             MPI_Comm_rank(comm, &rank);
36             if (rank == 0) {
37                 for (i = 0; i < remote_size; i++) {
38                     buf = -1;
39                     MPI_Recv(&buf, 1, MPI_INT, i, 0, comm, &status);
40                     if (buf != i) {
41                         errs++;
42                         fprintf(stderr, "buf = %d, should be %d\n", buf, i);
43                     }
44                 }
45             }
46         }
47         /* Now, reverse it and send back */
48         if (!leftGroup) {
49             MPI_Comm_rank(comm, &rank);
50             buf = rank;
51             MPI_Send(&buf, 1, MPI_INT, 0, 0, comm);
52         }
53         else {
54             MPI_Comm_remote_size(comm, &remote_size);
55             MPI_Comm_rank(comm, &rank);
56             if (rank == 0) {
57                 for (i = 0; i < remote_size; i++) {
58                     buf = -1;
59                     MPI_Recv(&buf, 1, MPI_INT, i, 0, comm, &status);
60                     if (buf != i) {
61                         errs++;
62                         fprintf(stderr, "buf = %d, should be %d\n", buf, i);
63                     }
64                 }
65             }
66         }
67         MTestFreeComm(&comm);
68     }
69
70     MTest_Finalize(errs);
71     MPI_Finalize();
72     return 0;
73 }