[MOAB-dev] commit/MOAB: danwu: Applied error handling code to parallel read for testing. If a file does not exist, or it is not recognized by MOAB, error messages and stack traces will be printed out (examples/TestErrorHandlingPar.cpp is updated to demonstrate this feature).
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue Feb 18 17:04:04 CST 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/e9651b84b830/
Changeset: e9651b84b830
Branch: error_handling_enhancement
User: danwu
Date: 2014-02-19 00:03:41
Summary: Applied error handling code to parallel read for testing. If a file does not exist, or it is not recognized by MOAB, error messages and stack traces will be printed out (examples/TestErrorHandlingPar.cpp is updated to demonstrate this feature).
Affected #: 3 files
diff --git a/examples/TestErrorHandlingPar.cpp b/examples/TestErrorHandlingPar.cpp
index 5245349..eed938c 100644
--- a/examples/TestErrorHandlingPar.cpp
+++ b/examples/TestErrorHandlingPar.cpp
@@ -2,10 +2,10 @@
* Description: Demonstrates enhanced error handling of parallel MOAB.\n
* This example tests MOAB's trace back error handler in parallel.\n
*
- * <b>To run</b>: mpiexec -np 4 ./TestErrorHandlingPar \n
+ * <b>To run</b>: mpiexec -np <n> ./TestErrorHandlingPar \n
*/
-#include "moab/Core.hpp" // Note, moab::Core is not used in this example
+#include "moab/Core.hpp"
#ifdef USE_MPI
#include "moab_mpi.h"
@@ -13,6 +13,7 @@
using namespace moab;
+// Functions that create and handle a contrived error
// Call hierarchy: A calls B, and B calls C
#ifdef USE_ERROR_INFO_CLASS
ErrorInfo FunctionC(int rank)
@@ -68,14 +69,74 @@ ErrorCode FunctionA(int rank)
return MB_SUCCESS;
}
+#endif
+#ifdef USE_ERROR_INFO_CLASS
// In this test case, MB_FILE_WRITE_ERROR is returned by FunctionC in each processor
-ErrorCode TestErrorHandlingPar(int rank)
+ErrorInfo TestErrorHandlingPar_1()
{
+ int rank = 0;
+#ifdef USE_MPI
+ MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+#endif
+
+ ErrorInfo err_info = FunctionA(rank);CHK_ERR(err_info);
+
+ return ERROR_INFO_SUCCESS;
+}
+#else
+// In this test case, MB_FILE_WRITE_ERROR is returned by FunctionC in each processor
+ErrorCode TestErrorHandlingPar_1()
+{
+ int rank = 0;
+#ifdef USE_MPI
+ MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+#endif
+
ErrorCode err_code = FunctionA(rank);CHK_ERR(err_code);
return MB_SUCCESS;
}
+
+// In this test case, a real error MB_FILE_DOES_NOT_EXIST is returned by MOAB
+ErrorCode TestErrorHandlingPar_2()
+{
+ Core moab;
+ Interface& mb = moab;
+
+ std::string opts;
+#ifdef USE_MPI
+ // Use parallel options
+ opts = std::string(";;PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL");
+#else
+ opts = std::string(";;");
+#endif
+
+ // Load a file that does not exist
+ ErrorCode rval = mb.load_file("no_such_file.nc", NULL, opts.c_str());CHK_ERR(rval);
+
+ return MB_SUCCESS;
+}
+
+// In this test case, a real error MB_INDEX_OUT_OF_RANGE is returned by MOAB
+ErrorCode TestErrorHandlingPar_3()
+{
+ Core moab;
+ Interface& mb = moab;
+
+ std::string opts;
+#ifdef USE_MPI
+ // Use parallel options
+ opts = std::string(";;PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL");
+#else
+ opts = std::string(";;");
+#endif
+
+ // Load a file that is not recognized by MOAB
+ ErrorCode rval = mb.load_file("TestErrorHandlingPar.cpp", NULL, opts.c_str());CHK_ERR(rval);
+
+ return MB_SUCCESS;
+}
#endif
int main(int argc, char** argv)
@@ -86,11 +147,14 @@ int main(int argc, char** argv)
MBErrorHandler_Init();
- int rank = 0;
-#ifdef USE_MPI
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+ TestErrorHandlingPar_1();
+
+#ifdef USE_ERROR_INFO_CLASS
+#else
+ TestErrorHandlingPar_2();
+
+ TestErrorHandlingPar_3();
#endif
- TestErrorHandlingPar(rank);
MBErrorHandler_Finalize();
diff --git a/src/Core.cpp b/src/Core.cpp
index 8012355..fed3285 100644
--- a/src/Core.cpp
+++ b/src/Core.cpp
@@ -479,10 +479,12 @@ ErrorCode Core::load_file( const char* file_name,
}
else if (rval != MB_ENTITY_NOT_FOUND)
return rval;
- if (set_tag_name && num_set_tag_vals)
- rval = ReadParallel(this,pcomm).load_file( file_name, file_set, opts, &sl );
- else
- rval = ReadParallel(this,pcomm).load_file( file_name, file_set, opts );
+ if (set_tag_name && num_set_tag_vals) {
+ rval = ReadParallel(this,pcomm).load_file( file_name, file_set, opts, &sl );CHK_ERR(rval);
+ }
+ else {
+ rval = ReadParallel(this,pcomm).load_file( file_name, file_set, opts );CHK_ERR(rval);
+ }
#else
mError->set_last_error( "PARALLEL option not valid, this instance"
" compiled for serial execution.\n" );
@@ -546,8 +548,10 @@ ErrorCode Core::serial_load_file( const char* file_name,
status = stat(file_name, &stat_data);
#endif
if (status) {
+ /*
mError->set_last_error( "%s: %s", file_name, strerror(errno) );
- //return MB_FILE_DOES_NOT_EXIST;
+ return MB_FILE_DOES_NOT_EXIST;
+ */
SET_ERR_STR(MB_FILE_DOES_NOT_EXIST, file_name << ": " << strerror(errno));
}
#if defined(WIN32) || defined(WIN64) || defined(MSC_VER)
diff --git a/src/parallel/ReadParallel.cpp b/src/parallel/ReadParallel.cpp
index fe4ed55..9d45a70 100644
--- a/src/parallel/ReadParallel.cpp
+++ b/src/parallel/ReadParallel.cpp
@@ -234,7 +234,7 @@ ErrorCode ReadParallel::load_file(const char **file_names,
subset_list, file_id_tag,
reader_rank, cputime,
resolve_dim, shared_dim,
- ghost_dim, bridge_dim, num_layers, addl_ents);
+ ghost_dim, bridge_dim, num_layers, addl_ents);CHK_ERR(result);
if (parallel_mode == POPT_BCAST_DELETE && !is_reader)
opts.mark_all_seen();
@@ -519,17 +519,23 @@ ErrorCode ReadParallel::load_file(const char **file_names,
if (MB_SUCCESS != tmp_result) {
result = tmp_result;
if (myPcomm->proc_config().proc_size() != 1) {
+ /*
std::ostringstream ostr;
ostr << "Failed in step " << ParallelActionsNames[*vit] << std::endl;
std::string tmp_str;
if (MB_SUCCESS == mbImpl->get_last_error(tmp_str)) ostr << tmp_str << std::endl;
RR(ostr.str());
+ */
+ if (MB_SUCCESS != result) {
+ SET_ERR_STR(result, "Failed in step " << ParallelActionsNames[*vit]);
+ }
}
break;
}
if (cputime) act_times[i] = MPI_Wtime();
}
+ CHK_ERR(result);
if (use_id_tag) {
ErrorCode tmp_result = mbImpl->tag_delete( id_tag );
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