File: probe_intercomm.c

package info (click to toggle)
mpich 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 251,828 kB
  • sloc: ansic: 1,323,147; cpp: 82,869; f90: 72,420; javascript: 40,763; perl: 28,296; sh: 19,399; python: 16,191; xml: 14,418; makefile: 9,468; fortran: 8,046; java: 4,635; pascal: 352; asm: 324; ruby: 176; awk: 27; lisp: 19; php: 8; sed: 4
file content (69 lines) | stat: -rw-r--r-- 1,967 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mpitest.h"

/*
static char MTEST_Descrip[] = "Test MPI_Probe() for an intercomm";
*/
#define MAX_DATA_LEN 100

int main(int argc, char *argv[])
{
    int errs = 0, recvlen, isLeft;
    MPI_Status status;
    int rank, size;
    MPI_Comm intercomm;
    char buf[MAX_DATA_LEN];
    const char *test_str = "test";

    MTest_Init(&argc, &argv);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    if (size < 2) {
        fprintf(stderr, "This test requires at least two processes.");
        MPI_Abort(MPI_COMM_WORLD, 1);
    }

    while (MTestGetIntercomm(&intercomm, &isLeft, 2)) {
        if (intercomm == MPI_COMM_NULL)
            continue;

        MPI_Comm_rank(intercomm, &rank);

        /* 0 ranks on each side communicate, everyone else does nothing */
        if (rank == 0) {
            if (isLeft) {
                recvlen = -1;
                MPI_Probe(0, 0, intercomm, &status);
                MPI_Get_count(&status, MPI_CHAR, &recvlen);
                if (recvlen != (strlen(test_str) + 1)) {
                    printf(" Error: recvlen (%d) != strlen(\"%s\")+1 (%d)\n", recvlen, test_str,
                           (int) strlen(test_str) + 1);
                    ++errs;
                }
                buf[0] = '\0';
                MPI_Recv(buf, recvlen, MPI_CHAR, 0, 0, intercomm, &status);
                if (strcmp(test_str, buf)) {
                    printf(" Error: strcmp(test_str,buf)!=0\n");
                    ++errs;
                }
            } else {
                strncpy(buf, test_str, 5);
                MPI_Send(buf, strlen(buf) + 1, MPI_CHAR, 0, 0, intercomm);
            }
        }
        MTestFreeComm(&intercomm);
    }

    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}