Blame test/mpi/coll/exscan2.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
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
Packit 0848f5
/*
Packit 0848f5
static char MTEST_Descrip[] = "Test MPI_Exscan (simple test)";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int errs = 0;
Packit 0848f5
    int rank, size;
Packit 0848f5
    int sendbuf[1], recvbuf[1];
Packit 0848f5
    MPI_Comm comm;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    comm = MPI_COMM_WORLD;
Packit 0848f5
    MPI_Comm_rank(comm, &rank;;
Packit 0848f5
    MPI_Comm_size(comm, &size);
Packit 0848f5
Packit 0848f5
    sendbuf[0] = rank;
Packit 0848f5
    recvbuf[0] = -2;
Packit 0848f5
Packit 0848f5
    MPI_Exscan(sendbuf, recvbuf, 1, MPI_INT, MPI_SUM, comm);
Packit 0848f5
Packit 0848f5
    /* Check the results.  rank 0 has no data.  Input is
Packit 0848f5
     * 0  1  2  3  4  5  6  7  8 ...
Packit 0848f5
     * Output is
Packit 0848f5
     * -  0  1  3  6 10 15 21 28 36
Packit 0848f5
     * (scan, not counting the contribution from the calling process)
Packit 0848f5
     */
Packit 0848f5
    if (rank > 0) {
Packit 0848f5
        int result = (((rank) * (rank - 1)) / 2);
Packit 0848f5
        /* printf("%d: %d\n", rank, result); */
Packit 0848f5
        if (recvbuf[0] != result) {
Packit 0848f5
            errs++;
Packit 0848f5
            fprintf(stderr, "Error in recvbuf = %d on %d, expected %d\n", recvbuf[0], rank, result);
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    else if (recvbuf[0] != -2) {
Packit 0848f5
        errs++;
Packit 0848f5
        fprintf(stderr, "Error in recvbuf on zero, is %d\n", recvbuf[0]);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}