1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2006 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
10 #include "mpitestconf.h"
14 int handlerCalled = 0;
16 /* Prototype to suppress compiler warnings */
17 void user_handler(MPI_File * fh, int *errcode, ...);
19 void user_handler(MPI_File * fh, int *errcode, ...)
21 if (*errcode != MPI_SUCCESS) {
24 printf("In user_handler with code %d\n", *errcode);
29 int main(int argc, char *argv[])
31 int rank, errs = 0, rc;
32 MPI_Errhandler ioerr_handler;
37 MTest_Init(&argc, &argv);
39 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
41 /* Create a file to which to attach the handler */
42 rc = MPI_File_open(MPI_COMM_WORLD, (char *) "/scratch/test.txt",
43 MPI_MODE_CREATE | MPI_MODE_WRONLY | MPI_MODE_DELETE_ON_CLOSE,
47 printf("Unable to open test.txt for writing\n");
50 rc = MPI_File_create_errhandler(user_handler, &ioerr_handler);
53 printf("MPI_File_create_Errhandler returned an error code: %d\n", rc);
56 rc = MPI_File_set_errhandler(fh, ioerr_handler);
59 printf("MPI_File_set_errhandler returned an error code: %d\n", rc);
62 /* avoid leaking the errhandler, safe because they have refcount semantics */
63 rc = MPI_Errhandler_free(&ioerr_handler);
66 printf("MPI_Errhandler_free returned an error code: %d\n", rc);
69 /* This should generate an error because the file mode is WRONLY */
70 rc = MPI_File_read_at(fh, 0, inbuf, 80, MPI_BYTE, &status);
71 if (handlerCalled != 1) {
73 printf("User-defined error handler was not called\n");
76 rc = MPI_File_close(&fh);
79 printf("MPI_File_close returned an error code: %d\n", rc);