1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
14 static char MTEST_Descrip[] = "Test MPI_Probe() for an intercomm";
16 #define MAX_DATA_LEN 100
18 int main(int argc, char *argv[])
20 int errs = 0, recvlen, isLeft;
24 char buf[MAX_DATA_LEN];
25 const char *test_str = "test";
27 MTest_Init(&argc, &argv);
29 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30 MPI_Comm_size(MPI_COMM_WORLD, &size);
33 fprintf(stderr, "This test requires at least two processes.");
34 MPI_Abort(MPI_COMM_WORLD, 1);
37 while (MTestGetIntercomm(&intercomm, &isLeft, 2)) {
38 if (intercomm == MPI_COMM_NULL)
41 MPI_Comm_rank(intercomm, &rank);
43 /* 0 ranks on each side communicate, everyone else does nothing */
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);
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");
62 strncpy(buf, test_str, 5);
63 MPI_Send(buf, strlen(buf) + 1, MPI_CHAR, 0, 0, intercomm);
66 MTestFreeComm(&intercomm);