forked from ESMCI/cime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ESMCI#1502 from NCAR/ejh_bail
Clean up of error handling macros
- Loading branch information
Showing
5 changed files
with
152 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* @file | ||
* Macros to handle errors in tests or libray code. | ||
* @author Ed Hartnett | ||
* @date 2019 | ||
* | ||
* @see https://github.com/NCAR/ParallelIO | ||
*/ | ||
|
||
#ifndef __PIO_ERROR__ | ||
#define __PIO_ERROR__ | ||
|
||
#include <config.h> | ||
#include <pio.h> | ||
|
||
/** | ||
* Handle non-MPI errors by printing error message and goto exit. This | ||
* is used in test code. | ||
*/ | ||
#define BAIL(e) do { \ | ||
fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \ | ||
goto exit; \ | ||
} while (0) | ||
|
||
/** | ||
* Handle non-MPI errors by calling pio_err(), setting return code, | ||
* and goto exit. This is used in library code. | ||
*/ | ||
#define EXIT(ios, e) do { \ | ||
ret = pio_err(NULL, NULL, e, __FILE__, __LINE__); \ | ||
goto exit; \ | ||
} while (0) | ||
|
||
/** | ||
* Same as the EXIT macro, but uses NULL for iosystem. | ||
*/ | ||
#define EXIT1(e) EXIT(NULL, e) | ||
|
||
/** | ||
* Handle non-MPI errors by finalizing the MPI library and exiting | ||
* with an exit code. | ||
*/ | ||
#define ERR(e) do { \ | ||
fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \ | ||
MPI_Finalize(); \ | ||
return e; \ | ||
} while (0) | ||
|
||
/** | ||
* Handle MPI errors. This should only be used with MPI library | ||
* function calls. Print error message, finalize MPI and return error | ||
* code. | ||
*/ | ||
#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. Print error message, finalize MPI 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__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.