[MOAB-dev] commit/MOAB: danwu: Supporting globally fatal errors (only printed from the root processor) and per-processor relevant errors (printed from current processor).
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Feb 19 15:03:10 CST 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/d463e03e3a14/
Changeset: d463e03e3a14
Branch: error_handling_enhancement
User: danwu
Date: 2014-02-19 22:02:46
Summary: Supporting globally fatal errors (only printed from the root processor) and per-processor relevant errors (printed from current processor).
Affected #: 2 files
diff --git a/src/ErrorHandler.cpp b/src/ErrorHandler.cpp
index 1b6ee56..8f0d30c 100644
--- a/src/ErrorHandler.cpp
+++ b/src/ErrorHandler.cpp
@@ -1,6 +1,8 @@
#include "moab/ErrorHandler.hpp"
#include "ErrorOutput.hpp"
+#include <stdlib.h>
+
namespace moab {
static ErrorOutput* errorOutput = NULL;
@@ -28,19 +30,29 @@ bool MBErrorHandler_Initialized()
void MBTraceBackErrorHandler(int line, const char* func, const char* file, const char* dir, const char* err_msg, ErrorType err_type)
{
- // Print the error message
- if (MB_ERROR_TYPE_NEW == err_type) {
- if (err_msg) {
- if (NULL != errorOutput) {
- errorOutput->print("--------------------- Error Message ------------------------------------\n");
- errorOutput->printf("%s!\n", err_msg);
- }
+ // For a globally fatal error, we get world rank of current processor, so that it is only printed from processor 0
+ // For a per-processor relevant error, we set rank of current processor to 0, so that it is always printed
+ int rank = 0;
+ if (MB_ERROR_TYPE_NEW_GLOBAL == err_type && NULL != errorOutput && errorOutput->have_rank())
+ rank = errorOutput->get_rank();
+
+ if (0 == rank) {
+ // Print the error messages if it is a new error
+ if (MB_ERROR_TYPE_EXISTING != err_type && NULL != errorOutput && NULL != err_msg) {
+ errorOutput->print("--------------------- Error Message ------------------------------------\n");
+ errorOutput->printf("%s!\n", err_msg);
}
- }
- // Print a line of stack trace
- if (NULL != errorOutput)
- errorOutput->printf("%s() line %d in %s%s\n", func, line, dir, file);
+ // Print a line of stack trace
+ if (NULL != errorOutput)
+ errorOutput->printf("%s() line %d in %s%s\n", func, line, dir, file);
+ }
+ else {
+ // Do not print the error messages, since processor 0 will print them
+ // Sleep 10 seconds before aborting so it will not accidently kill process 0
+ sleep(10);
+ abort();
+ }
}
#ifdef USE_ERROR_INFO_CLASS
diff --git a/src/moab/ErrorHandler.hpp b/src/moab/ErrorHandler.hpp
index 99f6daa..42c1758 100644
--- a/src/moab/ErrorHandler.hpp
+++ b/src/moab/ErrorHandler.hpp
@@ -17,7 +17,9 @@
namespace moab {
-enum ErrorType { MB_ERROR_TYPE_NEW = 0, MB_ERROR_TYPE_EXISTING = 1 };
+//! ErrorType - passed to the error handling routines indicating if this is a new error (globally fatal
+//! or per-processor relevant) or an existing one
+enum ErrorType { MB_ERROR_TYPE_NEW_GLOBAL = 0, MB_ERROR_TYPE_NEW_LOCAL = 1, MB_ERROR_TYPE_EXISTING = 2 };
#ifdef USE_ERROR_INFO_CLASS
//! This class will replace the ErrorCode return codes in most cases
@@ -119,15 +121,26 @@ ErrorCode MBError(int line, const char* func, const char* file, const char* dir,
#ifdef USE_ERROR_INFO_CLASS
#define SET_ERR(err_code, err_msg) \
- return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, ErrorInfo(err_code, err_msg), MB_ERROR_TYPE_NEW)
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, ErrorInfo(err_code, err_msg), MB_ERROR_TYPE_NEW_LOCAL)
#define SET_ERR1(err_info) \
- return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_info, MB_ERROR_TYPE_NEW)
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_info, MB_ERROR_TYPE_NEW_LOCAL)
#define SET_ERR_STR(err_code, err_msg_str) \
ErrorInfo err_info; \
err_info << err_msg_str; \
- return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_info, MB_ERROR_TYPE_NEW)
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_info, MB_ERROR_TYPE_NEW_LOCAL)
+
+#define SET_GLB_ERR(err_code, err_msg) \
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, ErrorInfo(err_code, err_msg), MB_ERROR_TYPE_NEW_GLOBAL)
+
+#define SET_GLB_ERR1(err_info) \
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_info, MB_ERROR_TYPE_NEW_GLOBAL)
+
+#define SET_GLB_ERR_STR(err_code, err_msg_str) \
+ ErrorInfo err_info; \
+ err_info << err_msg_str; \
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_info, MB_ERROR_TYPE_NEW_GLOBAL)
#define CHK_ERR(err_info) \
do { \
@@ -180,12 +193,20 @@ ErrorCode MBError(int line, const char* func, const char* file, const char* dir,
} while (false)
#else
#define SET_ERR(err_code, err_msg) \
- return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_code, err_msg, MB_ERROR_TYPE_NEW)
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_code, err_msg, MB_ERROR_TYPE_NEW_LOCAL)
#define SET_ERR_STR(err_code, err_msg_str) \
std::ostringstream ostr; \
ostr << err_msg_str; \
- return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_code, ostr.str().c_str(), MB_ERROR_TYPE_NEW)
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_code, ostr.str().c_str(), MB_ERROR_TYPE_NEW_LOCAL)
+
+#define SET_GLB_ERR(err_code, err_msg) \
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_code, err_msg, MB_ERROR_TYPE_NEW_GLOBAL)
+
+#define SET_GLB_ERR_STR(err_code, err_msg_str) \
+ std::ostringstream ostr; \
+ ostr << err_msg_str; \
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_code, ostr.str().c_str(), MB_ERROR_TYPE_NEW_GLOBAL)
#define CHK_ERR(err_code) \
do { \
Repository URL: https://bitbucket.org/fathomteam/moab/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the moab-dev
mailing list