Blame test/mpi/comm/comm_idup_iallreduce.c

Packit Service c5cf8c
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit Service c5cf8c
/*
Packit Service c5cf8c
 *  (C) 2015 by Argonne National Laboratory.
Packit Service c5cf8c
 *      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
 */
Packit Service c5cf8c
Packit Service c5cf8c
#include <stdio.h>
Packit Service c5cf8c
#include <stdlib.h>
Packit Service c5cf8c
#include <string.h>
Packit Service c5cf8c
#include "mpi.h"
Packit Service c5cf8c
#include "mpitest.h"
Packit Service c5cf8c
Packit Service c5cf8c
#define ITERS 10
Packit Service c5cf8c
Packit Service c5cf8c
/* This test uses several scenarios to overlap iallreduce and comm_idup
Packit Service c5cf8c
 * 1.)  Use comm_idup  dublicate the COMM_WORLD and do iallreduce
Packit Service c5cf8c
 *      on the COMM_WORLD
Packit Service c5cf8c
 * 2.)  Do the above test in a loop
Packit Service c5cf8c
 * 3.)  Dublicate  COMM_WORLD, overalp iallreduce on one
Packit Service c5cf8c
 *      communicator with comm_idup on the nother communicator
Packit Service c5cf8c
 * 4.)  Split MPI_COMM_WORLD, communicate on the split communicator
Packit Service c5cf8c
        while dublicating COMM_WORLD
Packit Service c5cf8c
 *  5.) Duplicate the split communicators with comm_idup
Packit Service c5cf8c
 *      while communicating  onCOMM_WORLD
Packit Service c5cf8c
 *  6.) Ceate an inter-communicator and duplicate it with comm_idup while
Packit Service c5cf8c
 *      communicating on the inter-communicator
Packit Service c5cf8c
 *  7.) Dublicate the inter-communicator whil communicate on COMM_WORLD
Packit Service c5cf8c
 *  8.) Merge the inter-communicator to an intra-communicator and idup it,
Packit Service c5cf8c
 *      overlapping with communication on MPI_COMM_WORLD
Packit Service c5cf8c
 *  9.) Communicate on the merge communicator, while duplicating COMM_WORLD
Packit Service c5cf8c
*/
Packit Service c5cf8c
Packit Service c5cf8c
int main(int argc, char **argv)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int errs = 0;
Packit Service c5cf8c
    int i;
Packit Service c5cf8c
    int rank, size, lrank, lsize, rsize, isize;
Packit Service c5cf8c
    int in, out, sol;
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Comm newcomm, newcomm_v[ITERS], dup_comm, split, ic, merge;
Packit Service c5cf8c
    MPI_Request sreq[ITERS * 2];
Packit Service c5cf8c
Packit Service c5cf8c
    MTest_Init(&argc, &argv);
Packit Service c5cf8c
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit Service c5cf8c
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit Service c5cf8c
Packit Service c5cf8c
    if (size < 2) {
Packit Service c5cf8c
        printf("this test requires at least 2 processes\n");
Packit Service c5cf8c
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* set input buffer and compare buffer */
Packit Service c5cf8c
    in = 1;
Packit Service c5cf8c
    sol = size;
Packit Service c5cf8c
    MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[0]);
Packit Service c5cf8c
    MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[1]);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    /* Test results of overlapping allreduce */
Packit Service c5cf8c
    if (sol != out)
Packit Service c5cf8c
        errs++;
Packit Service c5cf8c
    /*Test new communicator */
Packit Service c5cf8c
    errs += MTestTestComm(newcomm);
Packit Service c5cf8c
    MPI_Comm_free(&newcomm);
Packit Service c5cf8c
Packit Service c5cf8c
    for (i = 0; i < ITERS; i++) {
Packit Service c5cf8c
        MPI_Comm_idup(MPI_COMM_WORLD, &newcomm_v[i], &sreq[i]);
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[i + ITERS]);
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Waitall(ITERS * 2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
Packit Service c5cf8c
    for (i = 0; i < ITERS; i++) {
Packit Service c5cf8c
        errs += MTestTestComm(newcomm_v[i]);
Packit Service c5cf8c
        MPI_Comm_free(&newcomm_v[i]);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Comm_dup(MPI_COMM_WORLD, &dup_comm);
Packit Service c5cf8c
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
Packit Service c5cf8c
        MPI_Comm_idup(dup_comm, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        MPI_Comm_idup(dup_comm, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    }
Packit Service c5cf8c
    /* Test Iallreduce */
Packit Service c5cf8c
    if (sol != out)
Packit Service c5cf8c
        errs++;
Packit Service c5cf8c
Packit Service c5cf8c
    /*Test new communicator */
Packit Service c5cf8c
    errs += MTestTestComm(newcomm);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Comm_free(&newcomm);
Packit Service c5cf8c
    MPI_Comm_free(&dup_comm);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Comm_split(MPI_COMM_WORLD, rank % 2, rank, &split);
Packit Service c5cf8c
    MPI_Comm_rank(split, &lrank);
Packit Service c5cf8c
    MPI_Comm_size(split, &lsize);
Packit Service c5cf8c
Packit Service c5cf8c
    sol = lsize;
Packit Service c5cf8c
    if (lrank == 0) {
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, split, &sreq[0]);
Packit Service c5cf8c
        MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, split, &sreq[0]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    }
Packit Service c5cf8c
    /* Test Iallreduce */
Packit Service c5cf8c
    if (sol != out)
Packit Service c5cf8c
        errs++;;
Packit Service c5cf8c
Packit Service c5cf8c
    /* Test new communicator */
Packit Service c5cf8c
    errs += MTestTestComm(newcomm);
Packit Service c5cf8c
    MPI_Comm_free(&newcomm);
Packit Service c5cf8c
    sol = size;
Packit Service c5cf8c
Packit Service c5cf8c
    if (lrank == 0) {
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
Packit Service c5cf8c
        MPI_Comm_idup(split, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        MPI_Comm_idup(split, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    }
Packit Service c5cf8c
    /* Test Iallreduce */
Packit Service c5cf8c
    if (sol != out)
Packit Service c5cf8c
        errs++;;
Packit Service c5cf8c
Packit Service c5cf8c
    /* Test new communicator */
Packit Service c5cf8c
    errs += MTestTestComm(newcomm);
Packit Service c5cf8c
    MPI_Comm_free(&newcomm);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Intercomm_create(split, 0, MPI_COMM_WORLD, (rank == 0 ? 1 : 0), 1234, &ic);
Packit Service c5cf8c
    MPI_Comm_remote_size(ic, &rsize);
Packit Service c5cf8c
Packit Service c5cf8c
    sol = rsize;
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Comm_idup(ic, &newcomm, &sreq[1]);
Packit Service c5cf8c
    MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, ic, &sreq[0]);
Packit Service c5cf8c
    MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
Packit Service c5cf8c
Packit Service c5cf8c
    if (sol != out)
Packit Service c5cf8c
        errs++;;
Packit Service c5cf8c
    /* Test new inter communicator */
Packit Service c5cf8c
    errs += MTestTestComm(newcomm);
Packit Service c5cf8c
    MPI_Comm_free(&newcomm);
Packit Service c5cf8c
Packit Service c5cf8c
    sol = lsize;
Packit Service c5cf8c
    if (lrank == 0) {
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, split, &sreq[0]);
Packit Service c5cf8c
        MPI_Comm_idup(ic, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        MPI_Comm_idup(ic, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, split, &sreq[0]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    }
Packit Service c5cf8c
    /* Test Iallreduce resutls for split-communicator */
Packit Service c5cf8c
    if (sol != out)
Packit Service c5cf8c
        errs++;;
Packit Service c5cf8c
    /* Test new inter-communicator */
Packit Service c5cf8c
Packit Service c5cf8c
    errs += MTestTestComm(newcomm);
Packit Service c5cf8c
    MPI_Comm_free(&newcomm);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Intercomm_merge(ic, rank % 2, &merge);
Packit Service c5cf8c
    MPI_Comm_size(merge, &isize);
Packit Service c5cf8c
Packit Service c5cf8c
    sol = size;
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
Packit Service c5cf8c
        MPI_Comm_idup(merge, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        MPI_Comm_idup(merge, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &sreq[0]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
Packit Service c5cf8c
    if (sol != out)
Packit Service c5cf8c
        errs++;;
Packit Service c5cf8c
    /* Test new communicator */
Packit Service c5cf8c
    errs += MTestTestComm(newcomm);
Packit Service c5cf8c
    MPI_Comm_free(&newcomm);
Packit Service c5cf8c
    sol = isize;
Packit Service c5cf8c
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, merge, &sreq[0]);
Packit Service c5cf8c
        MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        MPI_Comm_idup(MPI_COMM_WORLD, &newcomm, &sreq[1]);
Packit Service c5cf8c
        MPI_Iallreduce(&in, &out, 1, MPI_INT, MPI_SUM, merge, &sreq[0]);
Packit Service c5cf8c
        MPI_Waitall(2, sreq, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Comm_free(&merge);
Packit Service c5cf8c
    MPI_Comm_free(&newcomm);
Packit Service c5cf8c
    MPI_Comm_free(&split);
Packit Service c5cf8c
    MPI_Comm_free(&ic);
Packit Service c5cf8c
Packit Service c5cf8c
    MTest_Finalize(errs);
Packit Service c5cf8c
    return MTestReturnValue(errs);
Packit Service c5cf8c
}