[MOAB-dev] commit/MOAB: danwu: Add a new example ErrorHandlingModel to show how MOAB's enhanced error handling model works.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Feb 28 15:58:47 CST 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/9a8d18905f85/
Changeset:   9a8d18905f85
Branch:      error_handling_enhancement
User:        danwu
Date:        2014-02-28 22:58:20
Summary:     Add a new example ErrorHandlingModel to show how MOAB's enhanced error handling model works.

Affected #:  2 files

diff --git a/examples/ErrorHandlingModel.cpp b/examples/ErrorHandlingModel.cpp
new file mode 100644
index 0000000..5b89a44
--- /dev/null
+++ b/examples/ErrorHandlingModel.cpp
@@ -0,0 +1,104 @@
+/** @example ErrorHandlingModel.cpp
+ * Description: This example will show how MOAB's enhanced error handling model works. \n
+ * The errors are all contrived, used for illustration purpose only. \n
+ *
+ * <b>To run</b>: mpiexec -np 4 ./ErrorHandlingModel <test_case_num> \n
+ */
+
+#include "moab/ErrorHandler.hpp"
+#ifdef USE_MPI
+#include "moab_mpi.h"
+#endif
+
+#include <iostream>
+#include <stdlib.h>
+
+using namespace moab;
+using namespace std;
+
+#ifdef USE_ERROR_INFO_CLASS
+// TBD
+#else
+// Functions that create and handle contrived errors
+// Call hierarchy: A calls B, and B calls C
+ErrorCode FunctionC(int test_case_num, int rank)
+{
+  if (1 == test_case_num) {
+    // Simulate a global fatal error MB_NOT_IMPLEMENTED on all processors
+    // Note, it is only printed by root processor 0
+    SET_GLB_ERR(MB_NOT_IMPLEMENTED, "A contrived global error MB_NOT_IMPLEMENTED");
+  }
+  else if (2 == test_case_num) {
+    // Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on all processors
+    // Note, it is printed by all processors
+    SET_ERR_STR(MB_INDEX_OUT_OF_RANGE, "A contrived error MB_INDEX_OUT_OF_RANGE on processor " << rank);
+  }
+  else if (3 == test_case_num) {
+    // Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on all processors except root
+    // Note, it is printed by all non-root processors
+    if (0 != rank) {
+      SET_ERR_STR(MB_TYPE_OUT_OF_RANGE, "A contrived error MB_TYPE_OUT_OF_RANGE on processor " << rank);
+    }
+  }
+  else if (4 == test_case_num) {
+    // Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on processor 1
+    // Note, it is only printed by processor 1
+    if (1 == rank) {
+      SET_ERR(MB_INDEX_OUT_OF_RANGE, "A contrived error MB_INDEX_OUT_OF_RANGE on processor 1");
+    }
+
+    // Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on processor 3
+    // Note, it is only printed by processor 3
+    if (3 == rank) {
+      SET_ERR(MB_TYPE_OUT_OF_RANGE, "A contrived error MB_TYPE_OUT_OF_RANGE on processor 3");
+    }
+  }
+
+  return MB_SUCCESS;
+}
+
+ErrorCode FunctionB(int test_case_num, int rank)
+{
+  ErrorCode err_code = FunctionC(test_case_num, rank);CHK_ERR(err_code);
+
+  return MB_SUCCESS;
+}
+
+ErrorCode FunctionA(int test_case_num, int rank)
+{
+  ErrorCode err_code = FunctionB(test_case_num, rank);CHK_ERR(err_code);
+
+  return MB_SUCCESS;
+}
+#endif
+
+int main(int argc, char** argv)
+{
+  // The required arg is a test case number (1, 2, 3 or 4)
+  if (argc < 2) {
+    cout << "Usage: " << argv[0] << " <test_case_num>" << endl;
+    return 0;
+  }
+
+#ifdef USE_MPI
+  MPI_Init(&argc, &argv);
+#endif
+
+  MBErrorHandler_Init();
+
+  int test_case_num = atoi(argv[1]);
+  int rank = 0;
+#ifdef USE_MPI
+  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+#endif
+
+  ErrorCode rval = FunctionA(test_case_num, rank);CHK_ERR(rval);
+
+  MBErrorHandler_Finalize();
+
+#ifdef USE_MPI
+  MPI_Finalize();
+#endif
+
+  return 0;
+}

diff --git a/examples/makefile b/examples/makefile
index 6993b64..f61c689 100644
--- a/examples/makefile
+++ b/examples/makefile
@@ -10,7 +10,7 @@ MESH_DIR="../MeshFiles/unittest"
 EXAMPLES = HelloMOAB GetEntities SetsNTags LoadPartial structuredmesh StructuredMeshSimple DirectAccessWithHoles DirectAccessNoHoles point_in_elem_search DeformMeshRemap
 PAREXAMPLES = HelloParMOAB ReduceExchangeTags LloydRelaxation CrystalRouterExample
 EXOIIEXAMPLES = TestExodusII
-ERROREXAMPLES = TestErrorHandling TestErrorHandlingPar
+ERROREXAMPLES = TestErrorHandling TestErrorHandlingPar ErrorHandlingModel
 F90EXAMPLES = DirectAccessNoHolesF90 PushParMeshIntoMoabF90
 
 default: ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${ERROREXAMPLES} ${F90EXAMPLES}
@@ -72,6 +72,9 @@ TestErrorHandling: TestErrorHandling.o ${MOAB_LIBDIR}/libMOAB.la
 TestErrorHandlingPar: TestErrorHandlingPar.o ${MOAB_LIBDIR}/libMOAB.la
 	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
 
+ErrorHandlingModel: ErrorHandlingModel.o ${MOAB_LIBDIR}/libMOAB.la
+	${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
+
 clean:
 	rm -rf *.o *.mod *.h5m ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${ERROREXAMPLES} ${F90EXAMPLES}

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