|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* (C) 2013 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* This test checks for proper error checking in MPI_Reduce_local, especially
|
|
Packit |
0848f5 |
* handling of MPI_IN_PLACE and buffer aliasing. */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include <stdlib.h>
|
|
Packit |
0848f5 |
#include <assert.h>
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include "mpitest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* quick cop-out for now */
|
|
Packit |
0848f5 |
#define check(c_) assert(c_)
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int err, errs = 0, len, i, errclass;
|
|
Packit |
0848f5 |
int rank = -1, size = -1;
|
|
Packit |
0848f5 |
int *buf;
|
|
Packit |
0848f5 |
int *recvbuf;
|
|
Packit |
0848f5 |
char msg[MPI_MAX_ERROR_STRING];
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit |
0848f5 |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
buf = malloc(size * sizeof(int));
|
|
Packit |
0848f5 |
recvbuf = malloc(size * sizeof(int));
|
|
Packit |
0848f5 |
for (i = 0; i < size; ++i) {
|
|
Packit |
0848f5 |
buf[i] = i;
|
|
Packit |
0848f5 |
recvbuf[i] = -1;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* check valid reduce_local does not fail */
|
|
Packit |
0848f5 |
err = MPI_Reduce_local(buf, recvbuf, size, MPI_INT, MPI_SUM);
|
|
Packit |
0848f5 |
check(err == MPI_SUCCESS);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* ERR: check inbuf==MPI_IN_PLACE */
|
|
Packit |
0848f5 |
err = MPI_Reduce_local(MPI_IN_PLACE, recvbuf, size, MPI_INT, MPI_SUM);
|
|
Packit |
0848f5 |
check(err != MPI_SUCCESS);
|
|
Packit |
0848f5 |
MPI_Error_class(err, &errclass);
|
|
Packit |
0848f5 |
check(errclass == MPI_ERR_BUFFER);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* ERR: check inoutbuf==MPI_IN_PLACE */
|
|
Packit |
0848f5 |
err = MPI_Reduce_local(buf, MPI_IN_PLACE, size, MPI_INT, MPI_SUM);
|
|
Packit |
0848f5 |
check(err != MPI_SUCCESS);
|
|
Packit |
0848f5 |
MPI_Error_class(err, &errclass);
|
|
Packit |
0848f5 |
check(errclass == MPI_ERR_BUFFER);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* ERR: check buffer aliasing is caught */
|
|
Packit |
0848f5 |
err = MPI_Reduce_local(recvbuf, recvbuf, size, MPI_INT, MPI_SUM);
|
|
Packit |
0848f5 |
check(err != MPI_SUCCESS);
|
|
Packit |
0848f5 |
MPI_Error_class(err, &errclass);
|
|
Packit |
0848f5 |
check(errclass == MPI_ERR_BUFFER);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
free(recvbuf);
|
|
Packit |
0848f5 |
free(buf);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|