Blame test/mpi/comm/comm_idup_isend.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2015 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include <string.h>
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
#define ITERS 4
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int errs = 0;
Packit 0848f5
    int i, j;
Packit 0848f5
    int rank, size, rsize;
Packit 0848f5
    int in[ITERS], out[ITERS], sol[ITERS], cnt;
Packit 0848f5
    int isLeft;
Packit 0848f5
    MPI_Comm newcomm[ITERS], testcomm;
Packit 0848f5
    MPI_Request *sreq;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit 0848f5
    if (size < 2) {
Packit 0848f5
        printf("this test requires at least 2 processes\n");
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    sreq = (MPI_Request *) malloc(sizeof(MPI_Request) * (size + 1) * ITERS);
Packit 0848f5
Packit 0848f5
    while (MTestGetIntracommGeneral(&testcomm, 1, 1)) {
Packit 0848f5
        if (testcomm == MPI_COMM_NULL)
Packit 0848f5
            continue;
Packit 0848f5
Packit 0848f5
        MPI_Comm_rank(testcomm, &rank;;
Packit 0848f5
        MPI_Comm_size(testcomm, &size);
Packit 0848f5
        cnt = 0;
Packit 0848f5
        for (j = 0; j < ITERS; j++) {
Packit 0848f5
            if (rank == 0) {
Packit 0848f5
                out[j] = 815;
Packit 0848f5
                in[j] = 815;
Packit 0848f5
                sol[j] = 815;
Packit 0848f5
                for (i = 1; i < size; i++)
Packit 0848f5
                    MPI_Isend(&out[j], 1, MPI_INT, i, 0, testcomm, &sreq[cnt++]);
Packit 0848f5
                MPI_Comm_idup(testcomm, &newcomm[j], &sreq[cnt++]);
Packit 0848f5
            }
Packit 0848f5
            else {
Packit 0848f5
                out[j] = 0;
Packit 0848f5
                in[j] = 0;
Packit 0848f5
                sol[j] = 815;
Packit 0848f5
                MPI_Comm_idup(testcomm, &newcomm[j], &sreq[cnt++]);
Packit 0848f5
                MPI_Irecv(&in[j], 1, MPI_INT, 0, 0, testcomm, &sreq[cnt++]);
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
        MPI_Waitall(cnt, sreq, MPI_STATUS_IGNORE);
Packit 0848f5
Packit 0848f5
        for (j = 0; j < ITERS; j++) {
Packit 0848f5
            if (sol[j] != in[j])
Packit 0848f5
                errs++;
Packit 0848f5
            errs += MTestTestComm(newcomm[j]);
Packit 0848f5
            MPI_Comm_free(&newcomm[j]);
Packit 0848f5
        }
Packit 0848f5
        MTestFreeComm(&testcomm);
Packit 0848f5
    }
Packit 0848f5
    while (MTestGetIntercomm(&testcomm, &isLeft, 1)) {
Packit 0848f5
        if (testcomm == MPI_COMM_NULL)
Packit 0848f5
            continue;
Packit 0848f5
Packit 0848f5
        MPI_Comm_rank(testcomm, &rank;;
Packit 0848f5
        MPI_Comm_size(testcomm, &size);
Packit 0848f5
        MPI_Comm_remote_size(testcomm, &rsize);
Packit 0848f5
        cnt = 0;
Packit 0848f5
        for (j = 0; j < ITERS; j++) {
Packit 0848f5
            if (rank == 0) {
Packit 0848f5
                out[j] = 815;
Packit 0848f5
                in[j] = 815;
Packit 0848f5
                sol[j] = 815;
Packit 0848f5
                for (i = 1; i < rsize; i++)
Packit 0848f5
                    MPI_Isend(&out[j], 1, MPI_INT, i, 0, testcomm, &sreq[cnt++]);
Packit 0848f5
                MPI_Comm_idup(testcomm, &newcomm[j], &sreq[cnt++]);
Packit 0848f5
            }
Packit 0848f5
            else {
Packit 0848f5
                out[j] = 0;
Packit 0848f5
                in[j] = 0;
Packit 0848f5
                sol[j] = 815;
Packit 0848f5
                MPI_Comm_idup(testcomm, &newcomm[j], &sreq[cnt++]);
Packit 0848f5
                MPI_Irecv(&in[j], 1, MPI_INT, 0, 0, testcomm, &sreq[cnt++]);
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
        MPI_Waitall(cnt, sreq, MPI_STATUS_IGNORE);
Packit 0848f5
Packit 0848f5
        for (j = 0; j < ITERS; j++) {
Packit 0848f5
            if (sol[j] != in[j])
Packit 0848f5
                errs++;
Packit 0848f5
            errs += MTestTestComm(newcomm[j]);
Packit 0848f5
            MPI_Comm_free(&newcomm[j]);
Packit 0848f5
        }
Packit 0848f5
        MTestFreeComm(&testcomm);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    free(sreq);
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}