Mesh Oriented datABase
(version 5.5.1)
An array-based unstructured mesh library
ErrorHandlingSimulation.cpp
Go to the documentation of this file.
1
/** @example ErrorHandlingSimulation.cpp
2
* Description: This example simulates MOAB's enhanced error handling in parallel. \n
3
* All of the errors are contrived, used for simulation purpose only. \n
4
*
5
* Note: We do not need a moab instance for this example
6
*
7
* <b>To run</b>: mpiexec -np 4 ./ErrorHandlingSimulation <test_case_num(1 to 4)> \n
8
*/
9
10
#include "
moab/MOABConfig.h
"
11
#include "
moab/ErrorHandler.hpp
"
12
#ifdef MOAB_HAVE_MPI
13
#include "
moab_mpi.h
"
14
#endif
15
16
#include <iostream>
17
#include <cstdlib>
18
19
using namespace
moab
;
20
using namespace
std;
21
22
// Functions that create and handle contrived errors
23
// Call hierarchy: A calls B, and B calls C
24
ErrorCode
FunctionC
(
int
test_case_num,
int
rank )
25
{
26
switch
( test_case_num )
27
{
28
case
1:
29
// Simulate a global fatal error MB_NOT_IMPLEMENTED on all processors
30
// Note, it is printed by root processor 0 only
31
MB_SET_GLB_ERR
(
MB_NOT_IMPLEMENTED
,
"A contrived global error MB_NOT_IMPLEMENTED"
);
32
break
;
33
case
2:
34
// Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on all processors
35
// Note, it is printed by all processors
36
MB_SET_ERR
(
MB_INDEX_OUT_OF_RANGE
,
"A contrived error MB_INDEX_OUT_OF_RANGE on processor "
<< rank );
37
break
;
38
case
3:
39
// Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on all processors except
40
// root Note, it is printed by all non-root processors
41
if
( 0 != rank )
42
MB_SET_ERR
(
MB_TYPE_OUT_OF_RANGE
,
"A contrived error MB_TYPE_OUT_OF_RANGE on processor "
<< rank );
43
break
;
44
case
4:
45
// Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on processor 1
46
// Note, it is printed by processor 1 only
47
if
( 1 == rank )
48
MB_SET_ERR
(
MB_INDEX_OUT_OF_RANGE
,
"A contrived error MB_INDEX_OUT_OF_RANGE on processor 1"
);
49
50
// Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on processor 3
51
// Note, it is printed by processor 3 only
52
if
( 3 == rank )
MB_SET_ERR
(
MB_TYPE_OUT_OF_RANGE
,
"A contrived error MB_TYPE_OUT_OF_RANGE on processor 3"
);
53
break
;
54
default
:
55
break
;
56
}
57
58
return
MB_SUCCESS
;
59
}
60
61
ErrorCode
FunctionB
(
int
test_case_num,
int
rank )
62
{
63
ErrorCode
err_code =
FunctionC
( test_case_num, rank );
MB_CHK_ERR
( err_code );
64
65
return
MB_SUCCESS
;
66
}
67
68
ErrorCode
FunctionA
(
int
test_case_num,
int
rank )
69
{
70
ErrorCode
err_code =
FunctionB
( test_case_num, rank );
MB_CHK_ERR
( err_code );
71
72
return
MB_SUCCESS
;
73
}
74
75
int
main
(
int
argc,
char
** argv )
76
{
77
if
( argc < 2 )
78
{
79
cout <<
"Usage: "
<< argv[0] <<
" <test_case_num(1 to 4)>"
<< endl;
80
return
0;
81
}
82
83
#ifdef MOAB_HAVE_MPI
84
MPI_Init( &argc, &argv );
85
#endif
86
87
// Initialize error handler, required for this example (not using a moab instance)
88
MBErrorHandler_Init
();
89
90
int
test_case_num = atoi( argv[1] );
91
int
rank = 0;
92
#ifdef MOAB_HAVE_MPI
93
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
94
#endif
95
96
ErrorCode
rval =
FunctionA
( test_case_num, rank );
MB_CHK_ERR
( rval );
97
98
// Finalize error handler, required for this example (not using a moab instance)
99
MBErrorHandler_Finalize
();
100
101
#ifdef MOAB_HAVE_MPI
102
MPI_Finalize();
103
#endif
104
105
return
0;
106
}
examples
basic
ErrorHandlingSimulation.cpp
Generated on Tue Oct 29 2024 02:05:40 for Mesh Oriented datABase by
1.9.1.