1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
/* This test is almost the same as commcall.c but uses old MPI functions:
* MPI_Errhandler_create() and MPI_Errhandler_set(). */
#include "mpi.h"
#include <stdio.h>
#include "mpitest.h"
/*
static char MTEST_Descrip[] = "Test comm_call_errhandler";
*/
static int calls = 0;
static int errs = 0;
static MPI_Comm mycomm;
void eh(MPI_Comm * comm, int *err, ...);
void eh(MPI_Comm * comm, int *err, ...)
{
if (*err != MPI_ERR_OTHER) {
errs++;
printf("Unexpected error code\n");
}
if (*comm != mycomm) {
errs++;
printf("Unexpected communicator\n");
}
calls++;
return;
}
int main(int argc, char *argv[])
{
MPI_Comm comm;
MPI_Errhandler newerr;
int i;
int reset_handler;
MTest_Init(&argc, &argv);
comm = MPI_COMM_WORLD;
mycomm = comm;
MPI_Errhandler_create(eh, &newerr);
MPI_Errhandler_set(comm, newerr);
/* There is no corresponding old function. */
MPI_Comm_call_errhandler(comm, MPI_ERR_OTHER);
MPI_Errhandler_free(&newerr);
if (calls != 1) {
errs++;
printf("Error handler not called\n");
}
/* Here we apply the test to many copies of a communicator */
for (reset_handler = 0; reset_handler <= 1; ++reset_handler) {
for (i = 0; i < 1000; i++) {
MPI_Comm comm2;
calls = 0;
MPI_Comm_dup(MPI_COMM_WORLD, &comm);
mycomm = comm;
MPI_Errhandler_create(eh, &newerr);
MPI_Errhandler_set(comm, newerr);
MPI_Comm_call_errhandler(comm, MPI_ERR_OTHER);
if (calls != 1) {
errs++;
printf("Error handler not called\n");
}
MPI_Comm_dup(comm, &comm2);
calls = 0;
mycomm = comm2;
/* comm2 must inherit the error handler from comm */
MPI_Comm_call_errhandler(comm2, MPI_ERR_OTHER);
if (calls != 1) {
errs++;
printf("Error handler not called\n");
}
if (reset_handler) {
/* extra checking of the reference count handling */
MPI_Errhandler_set(comm, MPI_ERRORS_ARE_FATAL);
}
MPI_Errhandler_free(&newerr);
MPI_Comm_free(&comm);
MPI_Comm_free(&comm2);
}
}
MTest_Finalize(errs);
return MTestReturnValue(errs);
}
|