1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2008 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
8 The MPI-2 specification makes it clear that delect attributes are
9 called on MPI_COMM_WORLD and MPI_COMM_SELF at the very beginning of
10 MPI_Finalize. This is useful for tools that want to perform the MPI
11 equivalent of an "at_exit" action.
17 int exit_key = MPI_KEYVAL_INVALID;
21 int delete_fn(MPI_Comm, int, void *, void *);
23 #define FFLUSH fflush(stdout);
28 int main(int argc, char **argv)
32 MTest_Init(&argc, &argv);
34 MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
36 /* create the keyval for the exit handler */
37 MPI_Keyval_create(MPI_NULL_COPY_FN, delete_fn, &exit_key, (void *) 0);
39 /* Attach to comm_self */
40 MPI_Attr_put(MPI_COMM_SELF, exit_key, (void *) 0);
41 /* We can free the key now */
42 MPI_Keyval_free(&exit_key);
45 /* MTest_Finalize(errs); */
48 /* Check that the exit handler was called, and without error */
50 /* In case more than one process exits MPI_Finalize */
53 printf("Attribute delete function on MPI_COMM_SELF was not called\n");
55 if (foundError != 0) {
57 printf("Found %d errors while executing delete function in MPI_COMM_SELF\n",
61 printf(" No Errors\n");
64 printf(" Found %d errors\n", errs);
72 int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)