Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
ErrorHandlingSimulation.cpp File Reference

Example demonstrating MOAB's enhanced error handling in parallel. More...

#include "moab/MOABConfig.h"
#include "moab/ErrorHandler.hpp"
#include <iostream>
#include <cstdlib>
#include <memory>
+ Include dependency graph for ErrorHandlingSimulation.cpp:

Go to the source code of this file.

Functions

ErrorCode FunctionC (int test_case_num, int rank)
 
ErrorCode FunctionB (int test_case_num, int rank)
 
ErrorCode FunctionA (int test_case_num, int rank)
 
int main (int argc, char **argv)
 

Detailed Description

Example demonstrating MOAB's enhanced error handling in parallel.

This example shows how to:

  • Initialize and finalize MOAB's error handler
  • Simulate different types of errors in parallel execution
  • Handle global fatal errors vs per-processor errors
  • Use error propagation through function call hierarchy
  • Demonstrate error reporting behavior across processors

The example demonstrates four test cases:

  • Test case 1: Global fatal error (MB_NOT_IMPLEMENTED) on all processors
  • Test case 2: Per-processor error (MB_INDEX_OUT_OF_RANGE) on all processors
  • Test case 3: Per-processor error (MB_TYPE_OUT_OF_RANGE) on non-root processors
  • Test case 4: Different errors on specific processors (1 and 3)
Author
MOAB Development Team
Date
2024

Description: This example simulates MOAB's enhanced error handling in parallel.
All of the errors are contrived, used for simulation purpose only.
Note: We do not need a moab instance for this example

To run: mpiexec -np 4 ./ErrorHandlingSimulation <test_case_num(1 to 4)>

Parameters
argcNumber of command line arguments
argvCommand line arguments array
Returns
0 on success, 1 on failure

Definition in file ErrorHandlingSimulation.cpp.

Function Documentation

◆ FunctionA()

ErrorCode FunctionA ( int  test_case_num,
int  rank 
)

Definition at line 93 of file ErrorHandlingSimulation.cpp.

94 {
95  MB_CHK_ERR( FunctionB( test_case_num, rank ) );
96 
97  return MB_SUCCESS;
98 }

References FunctionB(), MB_CHK_ERR, and MB_SUCCESS.

Referenced by main().

◆ FunctionB()

ErrorCode FunctionB ( int  test_case_num,
int  rank 
)

Definition at line 86 of file ErrorHandlingSimulation.cpp.

87 {
88  MB_CHK_ERR( FunctionC( test_case_num, rank ) );
89 
90  return MB_SUCCESS;
91 }

References FunctionC(), MB_CHK_ERR, and MB_SUCCESS.

Referenced by FunctionA().

◆ FunctionC()

ErrorCode FunctionC ( int  test_case_num,
int  rank 
)

Definition at line 49 of file ErrorHandlingSimulation.cpp.

50 {
51  switch( test_case_num )
52  {
53  case 1:
54  // Simulate a global fatal error MB_NOT_IMPLEMENTED on all processors
55  // Note, it is printed by root processor 0 only
56  MB_SET_GLB_ERR( MB_NOT_IMPLEMENTED, "A contrived global error MB_NOT_IMPLEMENTED" );
57  break;
58  case 2:
59  // Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on all processors
60  // Note, it is printed by all processors
61  MB_SET_ERR( MB_INDEX_OUT_OF_RANGE, "A contrived error MB_INDEX_OUT_OF_RANGE on processor " << rank );
62  break;
63  case 3:
64  // Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on all processors except
65  // root Note, it is printed by all non-root processors
66  if( 0 != rank )
67  MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "A contrived error MB_TYPE_OUT_OF_RANGE on processor " << rank );
68  break;
69  case 4:
70  // Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on processor 1
71  // Note, it is printed by processor 1 only
72  if( 1 == rank )
73  MB_SET_ERR( MB_INDEX_OUT_OF_RANGE, "A contrived error MB_INDEX_OUT_OF_RANGE on processor 1" );
74 
75  // Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on processor 3
76  // Note, it is printed by processor 3 only
77  if( 3 == rank ) MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "A contrived error MB_TYPE_OUT_OF_RANGE on processor 3" );
78  break;
79  default:
80  break;
81  }
82 
83  return MB_SUCCESS;
84 }

References MB_INDEX_OUT_OF_RANGE, MB_NOT_IMPLEMENTED, MB_SET_ERR, MB_SET_GLB_ERR, MB_SUCCESS, and MB_TYPE_OUT_OF_RANGE.

Referenced by FunctionB().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 100 of file ErrorHandlingSimulation.cpp.

101 {
102  if( argc < 2 )
103  {
104  cout << "Usage: " << argv[0] << " <test_case_num(1 to 4)>" << endl;
105  return 0;
106  }
107 
108 #ifdef MOAB_HAVE_MPI
109  MPI_Init( &argc, &argv );
110 #endif
111 
112  // Initialize error handler, required for this example (not using a moab instance)
114 
115  int test_case_num = atoi( argv[1] );
116  int rank = 0;
117 #ifdef MOAB_HAVE_MPI
118  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
119 #endif
120 
121  MB_CHK_ERR( FunctionA( test_case_num, rank ) );
122 
123  // Finalize error handler, required for this example (not using a moab instance)
125 
126 #ifdef MOAB_HAVE_MPI
127  MPI_Finalize();
128 #endif
129 
130  return 0;
131 }

References FunctionA(), MB_CHK_ERR, moab::MBErrorHandler_Finalize(), and moab::MBErrorHandler_Init().