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

Example demonstrating parallel error handling in MOAB. More...

#include "moab/Core.hpp"
#include <iostream>
#include <memory>
+ Include dependency graph for TestErrorHandlingPar.cpp:

Go to the source code of this file.

Functions

ErrorCode TestErrorHandlingPar_1 ()
 
ErrorCode TestErrorHandlingPar_2 ()
 
int main (int argc, char **argv)
 

Detailed Description

Example demonstrating parallel error handling in MOAB.

This example shows how to:

  • Initialize and finalize MOAB's error handler in parallel
  • Test different types of errors in parallel execution
  • Handle global fatal errors vs per-processor errors
  • Use parallel file loading with different partition methods

The example demonstrates two test cases:

  • Test case 1: Tests a global fatal error (MB_NOT_IMPLEMENTED)
  • Test case 2: Tests a per-processor error (MB_FAILURE)
Author
MOAB Development Team
Date
2024

Description: This example tests MOAB's trace back error handler in parallel.
To run: mpiexec -np n ./TestErrorHandlingPar <test_case_num(1 to 2)>

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

Definition in file TestErrorHandlingPar.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 81 of file TestErrorHandlingPar.cpp.

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 }

References ErrorCode, MB_CHK_ERR, MB_SUCCESS, moab::MBErrorHandler_Finalize(), moab::MBErrorHandler_Init(), TestErrorHandlingPar_1(), and TestErrorHandlingPar_2().

◆ TestErrorHandlingPar_1()

ErrorCode TestErrorHandlingPar_1 ( )

Definition at line 41 of file TestErrorHandlingPar.cpp.

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 }

References moab::Core::load_file(), mb, MB_CHK_ERR, MB_SUCCESS, and MESH_DIR.

Referenced by main().

◆ TestErrorHandlingPar_2()

ErrorCode TestErrorHandlingPar_2 ( )

Definition at line 62 of file TestErrorHandlingPar.cpp.

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 }

References moab::Core::load_file(), mb, MB_CHK_ERR, MB_SUCCESS, and MESH_DIR.

Referenced by main().