File: dupic.c

package info (click to toggle)
mpich 3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 131,836 kB
  • sloc: ansic: 975,868; cpp: 57,437; f90: 53,762; perl: 19,562; xml: 12,464; sh: 12,303; fortran: 7,875; makefile: 7,078; ruby: 126; java: 100; python: 98; lisp: 19; php: 8; sed: 4
file content (89 lines) | stat: -rw-r--r-- 3,304 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *
 *  (C) 2003 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */
#include "mpi.h"
#include <stdio.h>
#include "mpitest.h"

int main(int argc, char *argv[])
{
    int errs = 0;
    MPI_Comm comm, dupcomm, dupcomm2;
    MPI_Request rreq[2];
    int count;
    int indicies[2];
    int r1buf, r2buf, s1buf, s2buf;
    int rank, isLeft;

    MTest_Init(&argc, &argv);

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

        MPI_Comm_dup(comm, &dupcomm);

        /* Check that there are separate contexts.  We do this by setting
         * up nonblocking received on both communicators, and then
         * sending to them.  If the contexts are different, tests on the
         * unsatisfied communicator should indicate no available message */
        MPI_Comm_rank(comm, &rank);
        if (rank == 0) {
            s1buf = 456;
            s2buf = 17;
            r1buf = r2buf = -1;
            /* These are send/receives to the process with rank zero
             * in the other group (these are intercommunicators) */
            MPI_Irecv(&r1buf, 1, MPI_INT, 0, 0, dupcomm, &rreq[0]);
            MPI_Irecv(&r2buf, 1, MPI_INT, 0, 0, comm, &rreq[1]);
            MPI_Send(&s2buf, 1, MPI_INT, 0, 0, comm);
            MPI_Waitsome(2, rreq, &count, indicies, MPI_STATUSES_IGNORE);
            if (count != 1 || indicies[0] != 1) {
                /* The only valid return is that exactly one message
                 * has been received */
                errs++;
                if (count == 1 && indicies[0] != 1) {
                    printf("Error in context values for intercomm\n");
                } else if (count == 2) {
                    printf("Error: two messages received!\n");
                } else {
                    int i;
                    printf("Error: count = %d", count);
                    for (i = 0; i < count; i++) {
                        printf(" indicies[%d] = %d", i, indicies[i]);
                    }
                    printf("\n");
                }
            }

            /* Make sure that we do not send the next message until
             * the other process (rank zero in the other group)
             * has also completed the first step */
            MPI_Sendrecv(MPI_BOTTOM, 0, MPI_BYTE, 0, 37,
                         MPI_BOTTOM, 0, MPI_BYTE, 0, 37, comm, MPI_STATUS_IGNORE);

            /* Complete the receive on dupcomm */
            MPI_Send(&s1buf, 1, MPI_INT, 0, 0, dupcomm);
            MPI_Wait(&rreq[0], MPI_STATUS_IGNORE);
            if (r1buf != s1buf) {
                errs++;
                printf("Wrong value in communication on dupcomm %d != %d\n", r1buf, s1buf);
            }
            if (r2buf != s2buf) {
                errs++;
                printf("Wrong value in communication on comm %d != %d\n", r2buf, s2buf);
            }
        }
        /* Try to duplicate a duplicated intercomm.  (This caused problems
         * with some MPIs) */
        MPI_Comm_dup(dupcomm, &dupcomm2);
        MPI_Comm_free(&dupcomm2);
        MPI_Comm_free(&dupcomm);
        MTestFreeComm(&comm);
    }
    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}