Blame test/mpi/comm/dupic.c

Packit Service c5cf8c
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit Service c5cf8c
/*
Packit Service c5cf8c
 *
Packit Service c5cf8c
 *  (C) 2003 by Argonne National Laboratory.
Packit Service c5cf8c
 *      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
 */
Packit Service c5cf8c
#include "mpi.h"
Packit Service c5cf8c
#include <stdio.h>
Packit Service c5cf8c
#include "mpitest.h"
Packit Service c5cf8c
Packit Service c5cf8c
int main(int argc, char *argv[])
Packit Service c5cf8c
{
Packit Service c5cf8c
    int errs = 0;
Packit Service c5cf8c
    MPI_Comm comm, dupcomm, dupcomm2;
Packit Service c5cf8c
    MPI_Request rreq[2];
Packit Service c5cf8c
    int count;
Packit Service c5cf8c
    int indicies[2];
Packit Service c5cf8c
    int r1buf, r2buf, s1buf, s2buf;
Packit Service c5cf8c
    int rank, isLeft;
Packit Service c5cf8c
Packit Service c5cf8c
    MTest_Init(&argc, &argv);
Packit Service c5cf8c
Packit Service c5cf8c
    while (MTestGetIntercomm(&comm, &isLeft, 2)) {
Packit Service c5cf8c
        if (comm == MPI_COMM_NULL)
Packit Service c5cf8c
            continue;
Packit Service c5cf8c
Packit Service c5cf8c
        MPI_Comm_dup(comm, &dupcomm);
Packit Service c5cf8c
Packit Service c5cf8c
        /* Check that there are separate contexts.  We do this by setting
Packit Service c5cf8c
         * up nonblocking received on both communicators, and then
Packit Service c5cf8c
         * sending to them.  If the contexts are different, tests on the
Packit Service c5cf8c
         * unsatisfied communicator should indicate no available message */
Packit Service c5cf8c
        MPI_Comm_rank(comm, &rank;;
Packit Service c5cf8c
        if (rank == 0) {
Packit Service c5cf8c
            s1buf = 456;
Packit Service c5cf8c
            s2buf = 17;
Packit Service c5cf8c
            r1buf = r2buf = -1;
Packit Service c5cf8c
            /* These are send/receives to the process with rank zero
Packit Service c5cf8c
             * in the other group (these are intercommunicators) */
Packit Service c5cf8c
            MPI_Irecv(&r1buf, 1, MPI_INT, 0, 0, dupcomm, &rreq[0]);
Packit Service c5cf8c
            MPI_Irecv(&r2buf, 1, MPI_INT, 0, 0, comm, &rreq[1]);
Packit Service c5cf8c
            MPI_Send(&s2buf, 1, MPI_INT, 0, 0, comm);
Packit Service c5cf8c
            MPI_Waitsome(2, rreq, &count, indicies, MPI_STATUSES_IGNORE);
Packit Service c5cf8c
            if (count != 1 || indicies[0] != 1) {
Packit Service c5cf8c
                /* The only valid return is that exactly one message
Packit Service c5cf8c
                 * has been received */
Packit Service c5cf8c
                errs++;
Packit Service c5cf8c
                if (count == 1 && indicies[0] != 1) {
Packit Service c5cf8c
                    printf("Error in context values for intercomm\n");
Packit Service c5cf8c
                } else if (count == 2) {
Packit Service c5cf8c
                    printf("Error: two messages received!\n");
Packit Service c5cf8c
                } else {
Packit Service c5cf8c
                    int i;
Packit Service c5cf8c
                    printf("Error: count = %d", count);
Packit Service c5cf8c
                    for (i = 0; i < count; i++) {
Packit Service c5cf8c
                        printf(" indicies[%d] = %d", i, indicies[i]);
Packit Service c5cf8c
                    }
Packit Service c5cf8c
                    printf("\n");
Packit Service c5cf8c
                }
Packit Service c5cf8c
            }
Packit Service c5cf8c
Packit Service c5cf8c
            /* Make sure that we do not send the next message until
Packit Service c5cf8c
             * the other process (rank zero in the other group)
Packit Service c5cf8c
             * has also completed the first step */
Packit Service c5cf8c
            MPI_Sendrecv(MPI_BOTTOM, 0, MPI_BYTE, 0, 37,
Packit Service c5cf8c
                         MPI_BOTTOM, 0, MPI_BYTE, 0, 37, comm, MPI_STATUS_IGNORE);
Packit Service c5cf8c
Packit Service c5cf8c
            /* Complete the receive on dupcomm */
Packit Service c5cf8c
            MPI_Send(&s1buf, 1, MPI_INT, 0, 0, dupcomm);
Packit Service c5cf8c
            MPI_Wait(&rreq[0], MPI_STATUS_IGNORE);
Packit Service c5cf8c
            if (r1buf != s1buf) {
Packit Service c5cf8c
                errs++;
Packit Service c5cf8c
                printf("Wrong value in communication on dupcomm %d != %d\n", r1buf, s1buf);
Packit Service c5cf8c
            }
Packit Service c5cf8c
            if (r2buf != s2buf) {
Packit Service c5cf8c
                errs++;
Packit Service c5cf8c
                printf("Wrong value in communication on comm %d != %d\n", r2buf, s2buf);
Packit Service c5cf8c
            }
Packit Service c5cf8c
        }
Packit Service c5cf8c
        /* Try to duplicate a duplicated intercomm.  (This caused problems
Packit Service c5cf8c
         * with some MPIs) */
Packit Service c5cf8c
        MPI_Comm_dup(dupcomm, &dupcomm2);
Packit Service c5cf8c
        MPI_Comm_free(&dupcomm2);
Packit Service c5cf8c
        MPI_Comm_free(&dupcomm);
Packit Service c5cf8c
        MTestFreeComm(&comm);
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MTest_Finalize(errs);
Packit Service c5cf8c
    return MTestReturnValue(errs);
Packit Service c5cf8c
}