|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include <stdlib.h>
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include "mpitest.h"
|
|
Packit |
0848f5 |
#include "mpicolltest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int err, errs = 0, len, i;
|
|
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 |
err = MTest_Allreduce(buf, buf, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
if (!err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
if (rank == 0)
|
|
Packit |
0848f5 |
printf("Did not detect aliased arguments in MPI_Allreduce\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
/* Check that we can get a message for this error */
|
|
Packit |
0848f5 |
/* (This works if it does not SEGV or hang) */
|
|
Packit |
0848f5 |
MPI_Error_string(err, msg, &len;;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* This case is a bit stranger than the MPI_Allreduce case above, because
|
|
Packit |
0848f5 |
* the recvbuf argument is only relevant at the root. So without an extra
|
|
Packit |
0848f5 |
* communication step to return errors everywhere, it will be typical for
|
|
Packit |
0848f5 |
* rank 0 (the root) to return an error and all other ranks will return
|
|
Packit |
0848f5 |
* MPI_SUCCESS. In many implementations this can leave the non-root
|
|
Packit |
0848f5 |
* processes hung or yield unmatched unexpected messages on the root. So we
|
|
Packit |
0848f5 |
* do our best to carry on in this case by posting a second non-erroneous
|
|
Packit |
0848f5 |
* MPI_Reduce on any process that got back an error from the intentionally
|
|
Packit |
0848f5 |
* erroneous MPI_Reduce. */
|
|
Packit |
0848f5 |
err = MTest_Reduce(buf, ((rank == 0) ? buf : NULL), 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (!err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
if (rank == 0)
|
|
Packit |
0848f5 |
printf("Did not detect aliased arguments in MPI_Reduce\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
/* Check that we can get a message for this error */
|
|
Packit |
0848f5 |
/* (This works if it does not SEGV or hang) */
|
|
Packit |
0848f5 |
MPI_Error_string(err, msg, &len;;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
/* post a correct MPI_Reduce on any processes that got an error earlier */
|
|
Packit |
0848f5 |
err = MTest_Reduce(buf, recvbuf, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("make-up reduce failed on rank %d\n", rank);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* this case should _not_ trigger an error, thanks to Kenneth Inghram for
|
|
Packit |
0848f5 |
* reporting this bug in MPICH */
|
|
Packit |
0848f5 |
err =
|
|
Packit |
0848f5 |
MTest_Reduce(((rank == 0) ? MPI_IN_PLACE : buf), buf, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf
|
|
Packit |
0848f5 |
("Incorrectly reported aliased arguments in MPI_Reduce with MPI_IN_PLACE on rank %d\n",
|
|
Packit |
0848f5 |
rank);
|
|
Packit |
0848f5 |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit |
0848f5 |
printf("FAILED TO MPI_ABORT!!!\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* check for aliasing detection in MPI_Gather (tt#1006) */
|
|
Packit |
0848f5 |
err = MTest_Gather(buf, 1, MPI_INT, buf, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (!err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Did not detect aliased arguments in MPI_Gather\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
/* Check that we can get a message for this error */
|
|
Packit |
0848f5 |
/* (This works if it does not SEGV or hang) */
|
|
Packit |
0848f5 |
MPI_Error_string(err, msg, &len;;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
/* post a correct MPI_Gather on any processes that got an error earlier */
|
|
Packit |
0848f5 |
err = MTest_Gather(buf, 1, MPI_INT, recvbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("make-up gather failed on rank %d\n", rank);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* check for aliasing detection in MPI_Scatter (tt#1006) */
|
|
Packit |
0848f5 |
err = MPI_Scatter(buf, 1, MPI_INT, buf, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if (!err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Did not detect aliased arguments in MPI_Scatter\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
/* Check that we can get a message for this error */
|
|
Packit |
0848f5 |
/* (This works if it does not SEGV or hang) */
|
|
Packit |
0848f5 |
MPI_Error_string(err, msg, &len;;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
/* post a correct MPI_Scatter on any processes that got an error earlier */
|
|
Packit |
0848f5 |
err = MPI_Scatter(buf, 1, MPI_INT, recvbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("make-up scatter failed on rank %d\n", rank);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
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 |
}
|