Blame test/mpi/coll/nonblocking2.c

Packit Service c5cf8c
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit Service c5cf8c
/*
Packit Service c5cf8c
 *  (C) 2011 by Argonne National Laboratory.
Packit Service c5cf8c
 *      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
 */
Packit Service c5cf8c
Packit Service c5cf8c
/* A basic test of all 17 nonblocking collective operations specified by the
Packit Service c5cf8c
 * MPI-3 standard.  It only exercises the intracommunicator functionality,
Packit Service c5cf8c
 * does not use MPI_IN_PLACE, and only transmits/receives simple integer types
Packit Service c5cf8c
 * with relatively small counts.  It does check a few fancier issues, such as
Packit Service c5cf8c
 * ensuring that "premature user releases" of MPI_Op and MPI_Datatype objects
Packit Service c5cf8c
 * does not result in an error or segfault. */
Packit Service c5cf8c
Packit Service c5cf8c
#include "mpi.h"
Packit Service c5cf8c
#include <stdlib.h>
Packit Service c5cf8c
#include <stdio.h>
Packit Service c5cf8c
#include "mpitest.h"
Packit Service c5cf8c
Packit Service c5cf8c
#define COUNT (10)
Packit Service c5cf8c
#define PRIME (17)
Packit Service c5cf8c
Packit Service c5cf8c
#define my_assert(cond_)                                                  \
Packit Service c5cf8c
    do {                                                                  \
Packit Service c5cf8c
        if (!(cond_)) {                                                   \
Packit Service c5cf8c
            fprintf(stderr, "assertion (%s) failed, aborting\n", #cond_); \
Packit Service c5cf8c
            MPI_Abort(MPI_COMM_WORLD, 1);                                 \
Packit Service c5cf8c
        }                                                                 \
Packit Service c5cf8c
    } while (0)
Packit Service c5cf8c
Packit Service c5cf8c
static void sum_fn(void *invec, void *inoutvec, int *len, MPI_Datatype * datatype)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int i;
Packit Service c5cf8c
    int *in = invec;
Packit Service c5cf8c
    int *inout = inoutvec;
Packit Service c5cf8c
    for (i = 0; i < *len; ++i) {
Packit Service c5cf8c
        inout[i] = in[i] + inout[i];
Packit Service c5cf8c
    }
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
Packit Service c5cf8c
int main(int argc, char **argv)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int i, j;
Packit Service c5cf8c
    int rank, size;
Packit Service c5cf8c
    int *buf = NULL;
Packit Service c5cf8c
    int *recvbuf = NULL;
Packit Service c5cf8c
    int *sendcounts = NULL;
Packit Service c5cf8c
    int *recvcounts = NULL;
Packit Service c5cf8c
    int *sdispls = NULL;
Packit Service c5cf8c
    int *rdispls = NULL;
Packit Service c5cf8c
    int *sendtypes = NULL;
Packit Service c5cf8c
    int *recvtypes = NULL;
Packit Service c5cf8c
    signed char *buf_alias = NULL;
Packit Service c5cf8c
    MPI_Request req;
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
    buf = malloc(COUNT * size * sizeof(int));
Packit Service c5cf8c
    recvbuf = malloc(COUNT * size * sizeof(int));
Packit Service c5cf8c
    sendcounts = malloc(size * sizeof(int));
Packit Service c5cf8c
    recvcounts = malloc(size * sizeof(int));
Packit Service c5cf8c
    sdispls = malloc(size * sizeof(int));
Packit Service c5cf8c
    rdispls = malloc(size * sizeof(int));
Packit Service c5cf8c
    sendtypes = malloc(size * sizeof(MPI_Datatype));
Packit Service c5cf8c
    recvtypes = malloc(size * sizeof(MPI_Datatype));
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Ibcast */
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        if (rank == 0) {
Packit Service c5cf8c
            buf[i] = i;
Packit Service c5cf8c
        } else {
Packit Service c5cf8c
            buf[i] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Ibcast(buf, COUNT, MPI_INT, 0, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        if (buf[i] != i)
Packit Service c5cf8c
            printf("buf[%d]=%d i=%d\n", i, buf[i], i);
Packit Service c5cf8c
        my_assert(buf[i] == i);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Ibcast (again, but designed to stress scatter/allgather impls) */
Packit Service c5cf8c
    buf_alias = (signed char *) buf;
Packit Service c5cf8c
    my_assert(COUNT * size * sizeof(int) > PRIME);      /* sanity */
Packit Service c5cf8c
    for (i = 0; i < PRIME; ++i) {
Packit Service c5cf8c
        if (rank == 0)
Packit Service c5cf8c
            buf_alias[i] = i;
Packit Service c5cf8c
        else
Packit Service c5cf8c
            buf_alias[i] = 0xdb;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    for (i = PRIME; i < COUNT * size * sizeof(int); ++i) {
Packit Service c5cf8c
        buf_alias[i] = 0xbf;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Ibcast(buf_alias, PRIME, MPI_SIGNED_CHAR, 0, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (i = 0; i < PRIME; ++i) {
Packit Service c5cf8c
        if (buf_alias[i] != i)
Packit Service c5cf8c
            printf("buf_alias[%d]=%d i=%d\n", i, buf_alias[i], i);
Packit Service c5cf8c
        my_assert(buf_alias[i] == i);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Ibarrier */
Packit Service c5cf8c
    MPI_Ibarrier(MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Ireduce */
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        buf[i] = rank + i;
Packit Service c5cf8c
        recvbuf[i] = 0xdeadbeef;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Ireduce(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
            if (recvbuf[i] != ((size * (size - 1) / 2) + (i * size)))
Packit Service c5cf8c
                printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i],
Packit Service c5cf8c
                       ((size * (size - 1) / 2) + (i * size)));
Packit Service c5cf8c
            my_assert(recvbuf[i] == ((size * (size - 1) / 2) + (i * size)));
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* same again, use a user op and free it before the wait */
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPI_Op op = MPI_OP_NULL;
Packit Service c5cf8c
        MPI_Op_create(sum_fn, /*commute= */ 1, &op);
Packit Service c5cf8c
Packit Service c5cf8c
        for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
            buf[i] = rank + i;
Packit Service c5cf8c
            recvbuf[i] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPI_Ireduce(buf, recvbuf, COUNT, MPI_INT, op, 0, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
        MPI_Op_free(&op);
Packit Service c5cf8c
        MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
        if (rank == 0) {
Packit Service c5cf8c
            for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
                if (recvbuf[i] != ((size * (size - 1) / 2) + (i * size)))
Packit Service c5cf8c
                    printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i],
Packit Service c5cf8c
                           ((size * (size - 1) / 2) + (i * size)));
Packit Service c5cf8c
                my_assert(recvbuf[i] == ((size * (size - 1) / 2) + (i * size)));
Packit Service c5cf8c
            }
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Iallreduce */
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        buf[i] = rank + i;
Packit Service c5cf8c
        recvbuf[i] = 0xdeadbeef;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Iallreduce(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        if (recvbuf[i] != ((size * (size - 1) / 2) + (i * size)))
Packit Service c5cf8c
            printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i],
Packit Service c5cf8c
                   ((size * (size - 1) / 2) + (i * size)));
Packit Service c5cf8c
        my_assert(recvbuf[i] == ((size * (size - 1) / 2) + (i * size)));
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Ialltoallv (a weak test, neither irregular nor sparse) */
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        sendcounts[i] = COUNT;
Packit Service c5cf8c
        recvcounts[i] = COUNT;
Packit Service c5cf8c
        sdispls[i] = COUNT * i;
Packit Service c5cf8c
        rdispls[i] = COUNT * i;
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            buf[i * COUNT + j] = rank + (i * j);
Packit Service c5cf8c
            recvbuf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Ialltoallv(buf, sendcounts, sdispls, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT,
Packit Service c5cf8c
                   MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (rank * j))); */
Packit Service c5cf8c
            my_assert(recvbuf[i * COUNT + j] == (i + (rank * j)));
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Igather */
Packit Service c5cf8c
    for (i = 0; i < size * COUNT; ++i) {
Packit Service c5cf8c
        buf[i] = rank + i;
Packit Service c5cf8c
        recvbuf[i] = 0xdeadbeef;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Igather(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, 0, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        for (i = 0; i < size; ++i) {
Packit Service c5cf8c
            for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
                my_assert(recvbuf[i * COUNT + j] == i + j);
Packit Service c5cf8c
            }
Packit Service c5cf8c
        }
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        for (i = 0; i < size * COUNT; ++i) {
Packit Service c5cf8c
            my_assert(recvbuf[i] == 0xdeadbeef);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* same test again, just use a dup'ed datatype and free it before the wait */
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPI_Datatype type = MPI_DATATYPE_NULL;
Packit Service c5cf8c
        MPI_Type_dup(MPI_INT, &type);
Packit Service c5cf8c
Packit Service c5cf8c
        for (i = 0; i < size * COUNT; ++i) {
Packit Service c5cf8c
            buf[i] = rank + i;
Packit Service c5cf8c
            recvbuf[i] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPI_Igather(buf, COUNT, MPI_INT, recvbuf, COUNT, type, 0, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
        MPI_Type_free(&type);   /* should cause implementations that don't refcount
Packit Service c5cf8c
                                 * correctly to blow up or hang in the wait */
Packit Service c5cf8c
        MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
        if (rank == 0) {
Packit Service c5cf8c
            for (i = 0; i < size; ++i) {
Packit Service c5cf8c
                for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
                    my_assert(recvbuf[i * COUNT + j] == i + j);
Packit Service c5cf8c
                }
Packit Service c5cf8c
            }
Packit Service c5cf8c
        } else {
Packit Service c5cf8c
            for (i = 0; i < size * COUNT; ++i) {
Packit Service c5cf8c
                my_assert(recvbuf[i] == 0xdeadbeef);
Packit Service c5cf8c
            }
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Iscatter */
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            if (rank == 0)
Packit Service c5cf8c
                buf[i * COUNT + j] = i + j;
Packit Service c5cf8c
            else
Packit Service c5cf8c
                buf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
            recvbuf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Iscatter(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, 0, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
        my_assert(recvbuf[j] == rank + j);
Packit Service c5cf8c
    }
Packit Service c5cf8c
    if (rank != 0) {
Packit Service c5cf8c
        for (i = 0; i < size * COUNT; ++i) {
Packit Service c5cf8c
            /* check we didn't corrupt the sendbuf somehow */
Packit Service c5cf8c
            my_assert(buf[i] == 0xdeadbeef);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Iscatterv */
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        /* weak test, just test the regular case where all counts are equal */
Packit Service c5cf8c
        sendcounts[i] = COUNT;
Packit Service c5cf8c
        sdispls[i] = i * COUNT;
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            if (rank == 0)
Packit Service c5cf8c
                buf[i * COUNT + j] = i + j;
Packit Service c5cf8c
            else
Packit Service c5cf8c
                buf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
            recvbuf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Iscatterv(buf, sendcounts, sdispls, MPI_INT, recvbuf, COUNT, MPI_INT, 0, MPI_COMM_WORLD,
Packit Service c5cf8c
                  &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
        my_assert(recvbuf[j] == rank + j);
Packit Service c5cf8c
    }
Packit Service c5cf8c
    if (rank != 0) {
Packit Service c5cf8c
        for (i = 0; i < size * COUNT; ++i) {
Packit Service c5cf8c
            /* check we didn't corrupt the sendbuf somehow */
Packit Service c5cf8c
            my_assert(buf[i] == 0xdeadbeef);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    for (i = 1; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            /* check we didn't corrupt the rest of the recvbuf */
Packit Service c5cf8c
            my_assert(recvbuf[i * COUNT + j] == 0xdeadbeef);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Ireduce_scatter */
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        recvcounts[i] = COUNT;
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            buf[i * COUNT + j] = rank + i;
Packit Service c5cf8c
            recvbuf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Ireduce_scatter(buf, recvbuf, recvcounts, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
        my_assert(recvbuf[j] == (size * rank + ((size - 1) * size) / 2));
Packit Service c5cf8c
    }
Packit Service c5cf8c
    for (i = 1; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            /* check we didn't corrupt the rest of the recvbuf */
Packit Service c5cf8c
            my_assert(recvbuf[i * COUNT + j] == 0xdeadbeef);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Ireduce_scatter_block */
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            buf[i * COUNT + j] = rank + i;
Packit Service c5cf8c
            recvbuf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Ireduce_scatter_block(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
        my_assert(recvbuf[j] == (size * rank + ((size - 1) * size) / 2));
Packit Service c5cf8c
    }
Packit Service c5cf8c
    for (i = 1; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            /* check we didn't corrupt the rest of the recvbuf */
Packit Service c5cf8c
            my_assert(recvbuf[i * COUNT + j] == 0xdeadbeef);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Igatherv */
Packit Service c5cf8c
    for (i = 0; i < size * COUNT; ++i) {
Packit Service c5cf8c
        buf[i] = 0xdeadbeef;
Packit Service c5cf8c
        recvbuf[i] = 0xdeadbeef;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        buf[i] = rank + i;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        recvcounts[i] = COUNT;
Packit Service c5cf8c
        rdispls[i] = i * COUNT;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Igatherv(buf, COUNT, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, 0, MPI_COMM_WORLD,
Packit Service c5cf8c
                 &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        for (i = 0; i < size; ++i) {
Packit Service c5cf8c
            for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
                my_assert(recvbuf[i * COUNT + j] == i + j);
Packit Service c5cf8c
            }
Packit Service c5cf8c
        }
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        for (i = 0; i < size * COUNT; ++i) {
Packit Service c5cf8c
            my_assert(recvbuf[i] == 0xdeadbeef);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Ialltoall */
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            buf[i * COUNT + j] = rank + (i * j);
Packit Service c5cf8c
            recvbuf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Ialltoall(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (i * j))); */
Packit Service c5cf8c
            my_assert(recvbuf[i * COUNT + j] == (i + (rank * j)));
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Iallgather */
Packit Service c5cf8c
    for (i = 0; i < size * COUNT; ++i) {
Packit Service c5cf8c
        buf[i] = rank + i;
Packit Service c5cf8c
        recvbuf[i] = 0xdeadbeef;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Iallgather(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            my_assert(recvbuf[i * COUNT + j] == i + j);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Iallgatherv */
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            recvbuf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
        recvcounts[i] = COUNT;
Packit Service c5cf8c
        rdispls[i] = i * COUNT;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i)
Packit Service c5cf8c
        buf[i] = rank + i;
Packit Service c5cf8c
    MPI_Iallgatherv(buf, COUNT, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, MPI_COMM_WORLD,
Packit Service c5cf8c
                    &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            my_assert(recvbuf[i * COUNT + j] == i + j);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Iscan */
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        buf[i] = rank + i;
Packit Service c5cf8c
        recvbuf[i] = 0xdeadbeef;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Iscan(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        my_assert(recvbuf[i] == ((rank * (rank + 1) / 2) + (i * (rank + 1))));
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Iexscan */
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        buf[i] = rank + i;
Packit Service c5cf8c
        recvbuf[i] = 0xdeadbeef;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Iexscan(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (i = 0; i < COUNT; ++i) {
Packit Service c5cf8c
        if (rank == 0)
Packit Service c5cf8c
            my_assert(recvbuf[i] == 0xdeadbeef);
Packit Service c5cf8c
        else
Packit Service c5cf8c
            my_assert(recvbuf[i] == ((rank * (rank + 1) / 2) + (i * (rank + 1)) - (rank + i)));
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* MPI_Ialltoallw (a weak test, neither irregular nor sparse) */
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        sendcounts[i] = COUNT;
Packit Service c5cf8c
        recvcounts[i] = COUNT;
Packit Service c5cf8c
        sdispls[i] = COUNT * i * sizeof(int);
Packit Service c5cf8c
        rdispls[i] = COUNT * i * sizeof(int);
Packit Service c5cf8c
        sendtypes[i] = MPI_INT;
Packit Service c5cf8c
        recvtypes[i] = MPI_INT;
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            buf[i * COUNT + j] = rank + (i * j);
Packit Service c5cf8c
            recvbuf[i * COUNT + j] = 0xdeadbeef;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPI_Ialltoallw(buf, sendcounts, sdispls, sendtypes, recvbuf, recvcounts, rdispls, recvtypes,
Packit Service c5cf8c
                   MPI_COMM_WORLD, &req;;
Packit Service c5cf8c
    MPI_Wait(&req, MPI_STATUS_IGNORE);
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        for (j = 0; j < COUNT; ++j) {
Packit Service c5cf8c
            /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (rank * j))); */
Packit Service c5cf8c
            my_assert(recvbuf[i * COUNT + j] == (i + (rank * j)));
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    MTest_Finalize(0);
Packit Service c5cf8c
    free(buf);
Packit Service c5cf8c
    free(recvbuf);
Packit Service c5cf8c
    free(sendcounts);
Packit Service c5cf8c
    free(recvcounts);
Packit Service c5cf8c
    free(rdispls);
Packit Service c5cf8c
    free(sdispls);
Packit Service c5cf8c
    free(recvtypes);
Packit Service c5cf8c
    free(sendtypes);
Packit Service c5cf8c
    return 0;
Packit Service c5cf8c
}