|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2008 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
The MPI-2 specification makes it clear that delect attributes are
|
|
Packit Service |
c5cf8c |
called on MPI_COMM_WORLD and MPI_COMM_SELF at the very beginning of
|
|
Packit Service |
c5cf8c |
MPI_Finalize. This is useful for tools that want to perform the MPI
|
|
Packit Service |
c5cf8c |
equivalent of an "at_exit" action.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int exit_key = MPI_KEYVAL_INVALID;
|
|
Packit Service |
c5cf8c |
int wasCalled = 0;
|
|
Packit Service |
c5cf8c |
int foundError = 0;
|
|
Packit Service |
c5cf8c |
/* #define DEBUG */
|
|
Packit Service |
c5cf8c |
int delete_fn(MPI_Comm, int, void *, void *);
|
|
Packit Service |
c5cf8c |
#ifdef DEBUG
|
|
Packit Service |
c5cf8c |
#define FFLUSH fflush(stdout);
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define FFLUSH
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int errs = 0, wrank;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* create the keyval for the exit handler */
|
|
Packit Service |
c5cf8c |
MPI_Keyval_create(MPI_NULL_COPY_FN, delete_fn, &exit_key, (void *) 0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Attach to comm_self */
|
|
Packit Service |
c5cf8c |
MPI_Attr_put(MPI_COMM_SELF, exit_key, (void *) 0);
|
|
Packit Service |
c5cf8c |
/* We can free the key now */
|
|
Packit Service |
c5cf8c |
MPI_Keyval_free(&exit_key);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Now, exit MPI */
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Check that the exit handler was called, and without error */
|
|
Packit Service |
c5cf8c |
if (wrank == 0) {
|
|
Packit Service |
c5cf8c |
/* In case more than one process exits MPI_Finalize */
|
|
Packit Service |
c5cf8c |
if (wasCalled != 1) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("Attribute delete function on MPI_COMM_SELF was not called\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (foundError != 0) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("Found %d errors while executing delete function in MPI_COMM_SELF\n",
|
|
Packit Service |
c5cf8c |
foundError);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (errs == 0) {
|
|
Packit Service |
c5cf8c |
printf(" No Errors\n");
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
printf(" Found %d errors\n", errs);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int flag;
|
|
Packit Service |
c5cf8c |
wasCalled++;
|
|
Packit Service |
c5cf8c |
MPI_Finalized(&flag;;
|
|
Packit Service |
c5cf8c |
if (flag) {
|
|
Packit Service |
c5cf8c |
foundError++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
}
|