Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ae196ef43870bd9becd7b4f20f7bc549e322d96a
[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) continue;
26
27         if (leftGroup) {
28             MPI_Comm_rank( comm, &rank );
29             buf = rank;
30             MPI_Send( &buf, 1, MPI_INT, 0, 0, comm );
31         }
32         else {
33             MPI_Comm_remote_size( comm, &remote_size );
34             MPI_Comm_rank( comm, &rank );
35             if (rank == 0) {
36                 for (i=0; i<remote_size; i++) {
37                     buf = -1;
38                     MPI_Recv( &buf, 1, MPI_INT, i, 0, comm, &status );
39                     if (buf != i) {
40                         errs++;
41                         fprintf( stderr, "buf = %d, should be %d\n", buf, i );
42                     }
43                 }
44             }
45         }
46         /* Now, reverse it and send back */
47         if (!leftGroup) {
48             MPI_Comm_rank( comm, &rank );
49             buf = rank;
50             MPI_Send( &buf, 1, MPI_INT, 0, 0, comm );
51         }
52         else {
53             MPI_Comm_remote_size( comm, &remote_size );
54             MPI_Comm_rank( comm, &rank );
55             if (rank == 0) {
56                 for (i=0; i<remote_size; i++) {
57                     buf = -1;
58                     MPI_Recv( &buf, 1, MPI_INT, i, 0, comm, &status );
59                     if (buf != i) {
60                         errs++;
61                         fprintf( stderr, "buf = %d, should be %d\n", buf, i );
62                     }
63                 }
64             }
65         }
66         MTestFreeComm(&comm);
67     }
68
69     MTest_Finalize( errs );
70     MPI_Finalize();
71     return 0;
72 }