Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
ErrorHandlingSimulation.cpp
Go to the documentation of this file.
00001 /** @example ErrorHandlingSimulation.cpp
00002  * Description: This example simulates MOAB's enhanced error handling in parallel. \n
00003  * All of the errors are contrived, used for simulation purpose only. \n
00004  *
00005  * Note: We do not need a moab instance for this example
00006  *
00007  * <b>To run</b>: mpiexec -np 4 ./ErrorHandlingSimulation <test_case_num(1 to 4)> \n
00008  */
00009 
00010 #include "moab/MOABConfig.h"
00011 #include "moab/ErrorHandler.hpp"
00012 #ifdef MOAB_HAVE_MPI
00013 #include "moab_mpi.h"
00014 #endif
00015 
00016 #include <iostream>
00017 #include <cstdlib>
00018 
00019 using namespace moab;
00020 using namespace std;
00021 
00022 // Functions that create and handle contrived errors
00023 // Call hierarchy: A calls B, and B calls C
00024 ErrorCode FunctionC( int test_case_num, int rank )
00025 {
00026     switch( test_case_num )
00027     {
00028         case 1:
00029             // Simulate a global fatal error MB_NOT_IMPLEMENTED on all processors
00030             // Note, it is printed by root processor 0 only
00031             MB_SET_GLB_ERR( MB_NOT_IMPLEMENTED, "A contrived global error MB_NOT_IMPLEMENTED" );
00032             break;
00033         case 2:
00034             // Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on all processors
00035             // Note, it is printed by all processors
00036             MB_SET_ERR( MB_INDEX_OUT_OF_RANGE, "A contrived error MB_INDEX_OUT_OF_RANGE on processor " << rank );
00037             break;
00038         case 3:
00039             // Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on all processors except
00040             // root Note, it is printed by all non-root processors
00041             if( 0 != rank )
00042                 MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "A contrived error MB_TYPE_OUT_OF_RANGE on processor " << rank );
00043             break;
00044         case 4:
00045             // Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on processor 1
00046             // Note, it is printed by processor 1 only
00047             if( 1 == rank )
00048                 MB_SET_ERR( MB_INDEX_OUT_OF_RANGE, "A contrived error MB_INDEX_OUT_OF_RANGE on processor 1" );
00049 
00050             // Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on processor 3
00051             // Note, it is printed by processor 3 only
00052             if( 3 == rank ) MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "A contrived error MB_TYPE_OUT_OF_RANGE on processor 3" );
00053             break;
00054         default:
00055             break;
00056     }
00057 
00058     return MB_SUCCESS;
00059 }
00060 
00061 ErrorCode FunctionB( int test_case_num, int rank )
00062 {
00063     ErrorCode err_code = FunctionC( test_case_num, rank );MB_CHK_ERR( err_code );
00064 
00065     return MB_SUCCESS;
00066 }
00067 
00068 ErrorCode FunctionA( int test_case_num, int rank )
00069 {
00070     ErrorCode err_code = FunctionB( test_case_num, rank );MB_CHK_ERR( err_code );
00071 
00072     return MB_SUCCESS;
00073 }
00074 
00075 int main( int argc, char** argv )
00076 {
00077     if( argc < 2 )
00078     {
00079         cout << "Usage: " << argv[0] << " <test_case_num(1 to 4)>" << endl;
00080         return 0;
00081     }
00082 
00083 #ifdef MOAB_HAVE_MPI
00084     MPI_Init( &argc, &argv );
00085 #endif
00086 
00087     // Initialize error handler, required for this example (not using a moab instance)
00088     MBErrorHandler_Init();
00089 
00090     int test_case_num = atoi( argv[1] );
00091     int rank          = 0;
00092 #ifdef MOAB_HAVE_MPI
00093     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00094 #endif
00095 
00096     ErrorCode rval = FunctionA( test_case_num, rank );MB_CHK_ERR( rval );
00097 
00098     // Finalize error handler, required for this example (not using a moab instance)
00099     MBErrorHandler_Finalize();
00100 
00101 #ifdef MOAB_HAVE_MPI
00102     MPI_Finalize();
00103 #endif
00104 
00105     return 0;
00106 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines