Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
TestErrorHandlingPar.cpp
Go to the documentation of this file.
1 /**
2  * @file TestErrorHandlingPar.cpp
3  * @brief Example demonstrating parallel error handling in MOAB
4  *
5  * This example shows how to:
6  * - Initialize and finalize MOAB's error handler in parallel
7  * - Test different types of errors in parallel execution
8  * - Handle global fatal errors vs per-processor errors
9  * - Use parallel file loading with different partition methods
10  *
11  * The example demonstrates two test cases:
12  * - Test case 1: Tests a global fatal error (MB_NOT_IMPLEMENTED)
13  * - Test case 2: Tests a per-processor error (MB_FAILURE)
14  *
15  * @author MOAB Development Team
16  * @date 2024
17  *
18 
19  * Description: This example tests MOAB's trace back error handler in parallel.\n
20  *
21  * <b>To run</b>: mpiexec -np \c n ./TestErrorHandlingPar <test_case_num(1 to 2)> \n
22  *
23  * @param argc Number of command line arguments
24  * @param argv Command line arguments array
25  * @return 0 on success, 1 on failure
26  */
27 
28 #include "moab/Core.hpp"
29 #ifdef MOAB_HAVE_MPI
30 #include "moab_mpi.h"
31 #endif
32 
33 #include <iostream>
34 #include <memory>
35 
36 using namespace moab;
37 using namespace std;
38 
39 // In this test case, a global fatal error MB_NOT_IMPLEMENTED is returned by MOAB
40 // Note, it is printed by root processor 0 only
42 {
43  Core moab;
44  Interface& mb = moab;
45 
46  string opts = ";;";
47 #ifdef MOAB_HAVE_MPI
48  // Use parallel options
49  opts += "PARALLEL=READ_PART;PARTITION_METHOD=SQIJ";
50 #endif
51 
52  // Load a CAM-FV file and read a variable on edges (not supported yet)
53  string test_file = string( MESH_DIR ) + string( "/io/fv3x46x72.t.3.nc" );
54  opts += ";VARIABLE=US";
55  MB_CHK_ERR( mb.load_file( test_file.c_str(), NULL, opts.c_str() ) );
56 
57  return MB_SUCCESS;
58 }
59 
60 // In this test case, a per-processor relevant error MB_FAILURE is returned by MOAB
61 // Note, it is printed by all processors
63 {
64  Core moab;
65  Interface& mb = moab;
66 
67  string opts = ";;";
68 #ifdef MOAB_HAVE_MPI
69  // Use parallel options
70  opts += "PARALLEL=READ_PART;PARTITION_METHOD=UNKNOWN";
71 #endif
72 
73  // Load a CAM-FV file with an unknown partition method specified
74  string test_file = string( MESH_DIR ) + string( "/io/fv3x46x72.t.3.nc" );
75  opts += ";VARIABLE=T";
76  MB_CHK_ERR( mb.load_file( test_file.c_str(), NULL, opts.c_str() ) );
77 
78  return MB_SUCCESS;
79 }
80 
81 int main( int argc, char** argv )
82 {
83  if( argc < 2 )
84  {
85  cout << "Usage: " << argv[0] << " <test_case_num(1 to 2>" << endl;
86  return 0;
87  }
88 
89 #ifdef MOAB_HAVE_MPI
90  MPI_Init( &argc, &argv );
91 #endif
92 
93  // Initialize error handler, optional for this example (using moab instances)
95 
96  ErrorCode rval = MB_SUCCESS;
97 
98  int test_case_num = atoi( argv[1] );
99  switch( test_case_num )
100  {
101  case 1:
103  break;
104  case 2:
106  break;
107  default:
108  break;
109  }
110 
111  // Finalize error handler, optional for this example (using moab instances)
113 
114 #ifdef MOAB_HAVE_MPI
115  MPI_Finalize();
116 #endif
117 
118  return 0;
119 }