Blame test/mpi/errors/coll/noalias3.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2010 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/* This is a very weak sanity test that all nonblocking collectives specified by
Packit 0848f5
 * MPI-3 are present in the library and take arguments as expected.  This test
Packit 0848f5
 * does not check for progress, matching issues, or sensible output buffer
Packit 0848f5
 * values. */
Packit 0848f5
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
#define NUM_INTS (2)
Packit 0848f5
Packit 0848f5
#define my_assert(cond_)                                                  \
Packit 0848f5
    do {                                                                  \
Packit 0848f5
        if (!(cond_)) {                                                   \
Packit 0848f5
            fprintf(stderr, "assertion (%s) failed, aborting\n", #cond_); \
Packit 0848f5
            MPI_Abort(MPI_COMM_WORLD, 1);                                 \
Packit 0848f5
        }                                                                 \
Packit 0848f5
    } while (0)
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int errs = 0;
Packit 0848f5
    int i;
Packit 0848f5
    int rank, size;
Packit 0848f5
    int *sbuf = NULL;
Packit 0848f5
    int *rbuf = NULL;
Packit 0848f5
    int *scounts = NULL;
Packit 0848f5
    int *rcounts = NULL;
Packit 0848f5
    int *sdispls = NULL;
Packit 0848f5
    int *rdispls = NULL;
Packit 0848f5
    int *types = NULL;
Packit 0848f5
    MPI_Comm comm;
Packit 0848f5
    MPI_Request req;
Packit 0848f5
Packit 0848f5
    /* intentionally not using MTest_Init/MTest_Finalize in order to make it
Packit 0848f5
     * easy to take this test and use it as an NBC sanity test outside of the
Packit 0848f5
     * MPICH test suite */
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    comm = MPI_COMM_WORLD;
Packit 0848f5
Packit 0848f5
    MPI_Comm_size(comm, &size);
Packit 0848f5
    MPI_Comm_rank(comm, &rank;;
Packit 0848f5
Packit 0848f5
    MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
Packit 0848f5
Packit 0848f5
    /* enough space for every process to contribute at least NUM_INTS ints to any
Packit 0848f5
     * collective operation */
Packit 0848f5
    sbuf = malloc(NUM_INTS * size * sizeof(int));
Packit 0848f5
    my_assert(sbuf);
Packit 0848f5
    rbuf = malloc(NUM_INTS * size * sizeof(int));
Packit 0848f5
    my_assert(rbuf);
Packit 0848f5
    scounts = malloc(size * sizeof(int));
Packit 0848f5
    my_assert(scounts);
Packit 0848f5
    rcounts = malloc(size * sizeof(int));
Packit 0848f5
    my_assert(rcounts);
Packit 0848f5
    sdispls = malloc(size * sizeof(int));
Packit 0848f5
    my_assert(sdispls);
Packit 0848f5
    rdispls = malloc(size * sizeof(int));
Packit 0848f5
    my_assert(rdispls);
Packit 0848f5
    types = malloc(size * sizeof(int));
Packit 0848f5
    my_assert(types);
Packit 0848f5
Packit 0848f5
    for (i = 0; i < size; ++i) {
Packit 0848f5
        sbuf[2 * i] = i;
Packit 0848f5
        sbuf[2 * i + 1] = i;
Packit 0848f5
        rbuf[2 * i] = i;
Packit 0848f5
        rbuf[2 * i + 1] = i;
Packit 0848f5
        scounts[i] = NUM_INTS;
Packit 0848f5
        rcounts[i] = NUM_INTS;
Packit 0848f5
        sdispls[i] = i * NUM_INTS;
Packit 0848f5
        rdispls[i] = i * NUM_INTS;
Packit 0848f5
        types[i] = MPI_INT;
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    if (rank == 0 && MPI_SUCCESS ==
Packit 0848f5
        MPI_Igather(sbuf, NUM_INTS, MPI_INT, sbuf, NUM_INTS, MPI_INT, 0, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (rank == 0 && MPI_SUCCESS ==
Packit 0848f5
        MPI_Igatherv(sbuf, NUM_INTS, MPI_INT, sbuf, rcounts, rdispls, MPI_INT, 0, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (rank == 0 && MPI_SUCCESS ==
Packit 0848f5
        MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, sbuf, NUM_INTS, MPI_INT, 0, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (rank == 0 && MPI_SUCCESS ==
Packit 0848f5
        MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, sbuf, NUM_INTS, MPI_INT, 0, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS == MPI_Iallgather(&sbuf[rank], 1, MPI_INT, sbuf, 1, MPI_INT, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS ==
Packit 0848f5
        MPI_Iallgatherv(&sbuf[rank * rcounts[rank]], rcounts[rank], MPI_INT, sbuf, rcounts, rdispls,
Packit 0848f5
                        MPI_INT, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS == MPI_Ialltoall(sbuf, NUM_INTS, MPI_INT, sbuf, NUM_INTS, MPI_INT, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS ==
Packit 0848f5
        MPI_Ialltoallv(sbuf, scounts, sdispls, MPI_INT, sbuf, scounts, sdispls, MPI_INT, comm,
Packit 0848f5
                       &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS ==
Packit 0848f5
        MPI_Ialltoallw(sbuf, scounts, sdispls, types, sbuf, scounts, sdispls, types, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (rank == 0 && MPI_SUCCESS ==
Packit 0848f5
        MPI_Ireduce(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS == MPI_Iallreduce(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS == MPI_Ireduce_scatter(sbuf, sbuf, rcounts, MPI_INT, MPI_SUM, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS ==
Packit 0848f5
        MPI_Ireduce_scatter_block(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS == MPI_Iscan(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (MPI_SUCCESS == MPI_Iexscan(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req))
Packit 0848f5
        errs++;
Packit 0848f5
Packit 0848f5
    if (sbuf)
Packit 0848f5
        free(sbuf);
Packit 0848f5
    if (rbuf)
Packit 0848f5
        free(rbuf);
Packit 0848f5
    if (scounts)
Packit 0848f5
        free(scounts);
Packit 0848f5
    if (rcounts)
Packit 0848f5
        free(rcounts);
Packit 0848f5
    if (sdispls)
Packit 0848f5
        free(sdispls);
Packit 0848f5
    if (rdispls)
Packit 0848f5
        free(rdispls);
Packit 0848f5
    if (types)
Packit 0848f5
        free(types);
Packit 0848f5
Packit 0848f5
    if (rank == 0) {
Packit 0848f5
        if (errs)
Packit 0848f5
            fprintf(stderr, "Found %d errors\n", errs);
Packit 0848f5
        else
Packit 0848f5
            printf(" No errors\n");
Packit 0848f5
    }
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}