Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MPI_INFO_ENV ... Still does nothing for now
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / probe-intercomm.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 <stdlib.h>
10 #include <string.h>
11 #include "mpitest.h"
12
13 /*
14 static char MTEST_Descrip[] = "Test MPI_Probe() for an intercomm";
15 */
16 #define MAX_DATA_LEN 100
17
18 int main(int argc, char *argv[])
19 {
20     int errs = 0, recvlen, isLeft;
21     MPI_Status status;
22     int rank, size;
23     MPI_Comm intercomm;
24     char buf[MAX_DATA_LEN];
25     const char *test_str = "test";
26
27     MTest_Init(&argc, &argv);
28
29     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30     MPI_Comm_size(MPI_COMM_WORLD, &size);
31
32     if (size < 2) {
33         fprintf(stderr, "This test requires at least two processes.");
34         MPI_Abort(MPI_COMM_WORLD, 1);
35     }
36
37     while (MTestGetIntercomm(&intercomm, &isLeft, 2)) {
38         if (intercomm == MPI_COMM_NULL)
39             continue;
40
41         MPI_Comm_rank(intercomm, &rank);
42
43         /* 0 ranks on each side communicate, everyone else does nothing */
44         if (rank == 0) {
45             if (isLeft) {
46                 recvlen = -1;
47                 MPI_Probe(0, 0, intercomm, &status);
48                 MPI_Get_count(&status, MPI_CHAR, &recvlen);
49                 if (recvlen != (strlen(test_str) + 1)) {
50                     printf(" Error: recvlen (%d) != strlen(\"%s\")+1 (%d)\n", recvlen, test_str,
51                            (int) strlen(test_str) + 1);
52                     ++errs;
53                 }
54                 buf[0] = '\0';
55                 MPI_Recv(buf, recvlen, MPI_CHAR, 0, 0, intercomm, &status);
56                 if (strcmp(test_str, buf)) {
57                     printf(" Error: strcmp(test_str,buf)!=0\n");
58                     ++errs;
59                 }
60             }
61             else {
62                 strncpy(buf, test_str, 5);
63                 MPI_Send(buf, strlen(buf) + 1, MPI_CHAR, 0, 0, intercomm);
64             }
65         }
66         MTestFreeComm(&intercomm);
67     }
68
69     MTest_Finalize(errs);
70     MPI_Finalize();
71     return 0;
72 }