Blame test/mpi/coll/allred5.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2003 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
#include <assert.h>
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
static char MTEST_Descrip[] = "Test MPI_Allreduce with count greater than the number of processes";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
/* We make the error count global so that we can easily control the output
Packit 0848f5
   of error information (in particular, limiting it after the first 10
Packit 0848f5
   errors */
Packit 0848f5
int errs = 0;
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    MPI_Comm comm;
Packit 0848f5
    MPI_Datatype dtype;
Packit 0848f5
    int count, *bufin, *bufout, size, i, minsize = 1;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
Packit 0848f5
        if (comm == MPI_COMM_NULL) {
Packit 0848f5
            continue;
Packit 0848f5
        }
Packit 0848f5
        MPI_Comm_size(comm, &size);
Packit 0848f5
        count = size * 2;
Packit 0848f5
        bufin = (int *) malloc(count * sizeof(int));
Packit 0848f5
        bufout = (int *) malloc(count * sizeof(int));
Packit 0848f5
        if (!bufin || !bufout) {
Packit 0848f5
            fprintf(stderr, "Unable to allocated space for buffers (%d)\n", count);
Packit 0848f5
            MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
        }
Packit 0848f5
        for (i = 0; i < count; i++) {
Packit 0848f5
            bufin[i] = i;
Packit 0848f5
            bufout[i] = -1;
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        dtype = MPI_INT;
Packit 0848f5
        MPI_Allreduce(bufin, bufout, count, dtype, MPI_SUM, comm);
Packit 0848f5
        /* Check output */
Packit 0848f5
        for (i = 0; i < count; i++) {
Packit 0848f5
            if (bufout[i] != i * size) {
Packit 0848f5
                fprintf(stderr, "Expected bufout[%d] = %d but found %d\n", i, i * size, bufout[i]);
Packit 0848f5
                errs++;
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
        free(bufin);
Packit 0848f5
        free(bufout);
Packit 0848f5
        MTestFreeComm(&comm);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}