diff --git a/src/clib/pio_error.h b/src/clib/pio_error.h index af4b0ed04e0..4e33f5695b5 100644 --- a/src/clib/pio_error.h +++ b/src/clib/pio_error.h @@ -28,4 +28,31 @@ return e; \ } while (0) +/** Handle MPI errors. This should only be used with MPI library + * function calls. Finalize and return. */ +#define MPIERR(e) do { \ + MPI_Error_string(e, err_buffer, &resultlen); \ + fprintf(stderr, "MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \ + MPI_Finalize(); \ + return ERR_AWFUL; \ + } while (0) + +/** Handle MPI errors. This should only be used with MPI library + * function calls. Finalize and goto exit. */ +#define MPIBAIL(e) do { \ + MPI_Error_string(e, err_buffer, &resultlen); \ + fprintf(stderr, "MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \ + ret = NC_EIO; \ + goto exit; \ + } while (0) + +/** Global err buffer for MPI. When there is an MPI error, this buffer + * is used to store the error message that is associated with the MPI + * error. */ +char err_buffer[MPI_MAX_ERROR_STRING]; + +/** This is the length of the most recent MPI error message, stored + * int the global error string. */ +int resultlen; + #endif /* __PIO_ERROR__ */