[MOAB-dev] commit/MOAB: danwu: Adding example to simulate MOAB's enhanced error handling in parallel. All of the errors are contrived, used for simulation purpose only.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Jul 9 15:04:48 CDT 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/6917d60bfb59/
Changeset: 6917d60bfb59
Branch: danwu/error_handling_enhancement
User: danwu
Date: 2014-07-09 22:04:17
Summary: Adding example to simulate MOAB's enhanced error handling in parallel. All of the errors are contrived, used for simulation purpose only.
Affected #: 2 files
diff --git a/examples/ErrorHandlingSimulation.cpp b/examples/ErrorHandlingSimulation.cpp
new file mode 100644
index 0000000..ffdc831
--- /dev/null
+++ b/examples/ErrorHandlingSimulation.cpp
@@ -0,0 +1,100 @@
+/** @example ErrorHandlingSimulation.cpp
+ * Description: This example simulates MOAB's enhanced error handling in parallel. \n
+ * All of the errors are contrived, used for simulation purpose only. \n
+ *
+ * <b>To run</b>: mpiexec -np 4 ./ErrorHandlingSimulation <test_case_num(1 to 4)> \n
+ */
+
+#include "moab/ErrorHandler.hpp"
+#ifdef USE_MPI
+#include "moab_mpi.h"
+#endif
+
+#include <iostream>
+#include <stdlib.h>
+
+using namespace moab;
+using namespace std;
+
+// Functions that create and handle contrived errors
+// Call hierarchy: A calls B, and B calls C
+ErrorCode FunctionC(int test_case_num, int rank)
+{
+ switch (test_case_num) {
+ case 1:
+ // Simulate a global fatal error MB_NOT_IMPLEMENTED on all processors
+ // Note, it is printed by root processor 0 only
+ SET_GLB_ERR(MB_NOT_IMPLEMENTED, "A contrived global error MB_NOT_IMPLEMENTED");
+ break;
+ case 2:
+ // 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);
+ break;
+ case 3:
+ // 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);
+ break;
+ case 4:
+ // Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on processor 1
+ // Note, it is printed by processor 1 only
+ 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 printed by processor 3 only
+ if (3 == rank)
+ SET_ERR(MB_TYPE_OUT_OF_RANGE, "A contrived error MB_TYPE_OUT_OF_RANGE on processor 3");
+ break;
+ default:
+ break;
+ }
+
+ 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;
+}
+
+int main(int argc, char** argv)
+{
+ if (argc < 2) {
+ cout << "Usage: " << argv[0] << " <test_case_num(1 to 4)>" << 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 787c8d3..c4dd9e7 100644
--- a/examples/makefile
+++ b/examples/makefile
@@ -11,8 +11,9 @@ EXAMPLES = HelloMOAB GetEntities SetsNTags LoadPartial structuredmesh Structured
PAREXAMPLES = HelloParMOAB ReduceExchangeTags LloydRelaxation CrystalRouterExample
EXOIIEXAMPLES = TestExodusII
F90EXAMPLES = DirectAccessNoHolesF90 PushParMeshIntoMoabF90
+ERROREXAMPLES = ErrorHandlingSimulation
-default: ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${F90EXAMPLES}
+default: ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${F90EXAMPLES} ${ERROREXAMPLES}
HelloMOAB: HelloMOAB.o ${MOAB_LIBDIR}/libMOAB.la
${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
@@ -70,9 +71,12 @@ VisTags: VisTags.o ${MOAB_LIBDIR}/libMOAB.la
ReadWriteTest: ReadWriteTest.o ${MOAB_LIBDIR}/libMOAB.la
${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
-
+
+ErrorHandlingSimulation: ErrorHandlingSimulation.o ${MOAB_LIBDIR}/libMOAB.la
+ ${MOAB_CXX} -o $@ $< ${MOAB_LIBS_LINK}
+
clean:
- rm -rf *.o *.mod *.h5m ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${F90EXAMPLES}
+ rm -rf *.o *.mod *.h5m ${EXAMPLES} ${PAREXAMPLES} ${EXOIIEXAMPLES} ${F90EXAMPLES} ${ERROREXAMPLES}
.cpp.o:
${MOAB_CXX} ${CXXFLAGS} ${MOAB_CXXFLAGS} ${MOAB_CPPFLAGS} ${MOAB_INCLUDES} -DMESH_DIR=\"${MESH_DIR}\" -c $<
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