Changeset 850
- Timestamp:
- 04/14/08 17:03:38 (20 months ago)
- Location:
- mpich2/trunk
- Files:
-
- 4 modified
-
src/binding/cxx/buildiface (modified) (9 diffs)
-
src/include/mpi.h.in (modified) (1 diff)
-
src/mpi/errhan/errutil.c (modified) (1 diff)
-
test/mpi/errors/cxx/errhan/throwtest.cxx (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mpich2/trunk/src/binding/cxx/buildiface
r100 r850 406 406 # 'Create_keyval' => 'int', 407 407 'Free_keyval' => 'static:0:1', 408 'Call_errhandler' => 0, 408 # this routine is special and cannot be auto-generated 409 # 'Call_errhandler' => 0, 409 410 'Set_name' => '0:2', 410 411 'Get_name' => '0:3', … … 526 527 'Get_errhandler' => 'MPI_Errhandler', 527 528 'Set_errhandler' => 0, 528 'Call_errhandler' => 0, 529 # this routine is special and cannot be autogenerated 530 #'Call_errhandler' => 0, 529 531 ); 530 532 # %class_mpi2file = ( … … 590 592 'Fence' => '0', 591 593 'Get_group' => 'MPI_Group', 592 'Call_errhandler' => 0, 594 # this routine is special and cannot be auto-generated 595 #'Call_errhandler' => 0, 593 596 'Get_attr' => '0', 594 597 'Start' => '0', … … 1731 1734 # Errors_return is not quite right for errors-throw-exceptions, 1732 1735 # but it is close. 1733 print $OUTFD "const Errhandler ERRORS_THROW_EXCEPTIONS(MPI_ERRORS_ RETURN);\n";1736 print $OUTFD "const Errhandler ERRORS_THROW_EXCEPTIONS(MPI_ERRORS_THROW_EXCEPTIONS);\n"; 1734 1737 } 1735 1738 else { … … 2339 2342 return e1; 2340 2343 } 2344 2345 2346 // Call_errhandler implementations. These sadly must contain a bit of logic to 2347 // cover the ERRORS_THROW_EXCEPTIONS case. 2348 void Comm::Call_errhandler( int errorcode ) const 2349 { 2350 if (Get_errhandler() == ERRORS_THROW_EXCEPTIONS) { 2351 throw Exception(errorcode); // throw by value, catch by reference 2352 } 2353 MPIX_CALL( MPI_Comm_call_errhandler( (MPI_Comm) the_real_comm, errorcode )); 2354 } 2355 2356 void Win::Call_errhandler( int errorcode ) const 2357 { 2358 if (Get_errhandler() == ERRORS_THROW_EXCEPTIONS) { 2359 throw Exception(errorcode); // throw by value, catch by reference 2360 } 2361 MPIX_CALL( MPI_Win_call_errhandler( (MPI_Win) the_real_win, errorcode )); 2362 } 2363 2364 void File::Call_errhandler( int errorcode ) const 2365 { 2366 if (Get_errhandler() == MPI_ERRORS_THROW_EXCEPTIONS) { 2367 throw Exception(errorcode); // throw by value, catch by reference 2368 } 2369 MPIX_CALL( MPI_File_call_errhandler( (MPI_File) the_real_file, errorcode )); 2370 } 2371 2341 2372 \n"; 2342 2373 … … 2602 2633 # Add the routine to initialize MPI datatype names for the C++ datatypes 2603 2634 print $OUTFD " 2635 /* MT FIXME: this is not thread-safe */ 2604 2636 void MPIR_CXX_InitDatatypeNames( void ) 2605 2637 { … … 3056 3088 *(void **)attr_out = attr_in; return 0;} 3057 3089 static Errhandler Create_errhandler( Errhandler_fn * ); 3090 virtual void Call_errhandler( int errcode ) const; 3058 3091 \n"; 3059 3092 } … … 3066 3099 3067 3100 static Errhandler Create_errhandler( Errhandler_fn * ); 3101 virtual void Call_errhandler( int errcode ) const; 3068 3102 \n"; 3069 3103 } … … 3076 3110 3077 3111 static Errhandler Create_errhandler( Errhandler_fn * ); 3112 virtual void Call_errhandler( int errcode ) const; 3078 3113 3079 3114 typedef int Copy_attr_function(const Win& oldwin, int win_keyval, void* extra_state, void* attribute_val_in, void* attribute_val_out, bool& flag); -
mpich2/trunk/src/include/mpi.h.in
r820 r850 211 211 #define MPI_ERRORS_ARE_FATAL ((MPI_Errhandler)0x54000000) 212 212 #define MPI_ERRORS_RETURN ((MPI_Errhandler)0x54000001) 213 /* #define MPIR_ERRORS_WARN ((MPI_Errhandler)0x54000002) */ 213 /* MPI_ERRORS_THROW_EXCEPTIONS is not part of the MPI standard, it is here to 214 facilitate the c++ binding which has MPI::ERRORS_THROW_EXCEPTIONS. */ 215 #define MPI_ERRORS_THROW_EXCEPTIONS ((MPI_Errhandler)0x54000002) 214 216 typedef int MPI_Errhandler; 215 217 -
mpich2/trunk/src/mpi/errhan/errutil.c
r100 r850 113 113 114 114 /* Preallocated errorhandler objects */ 115 MPID_Errhandler MPID_Errhandler_builtin[ 2] =115 MPID_Errhandler MPID_Errhandler_builtin[3] = 116 116 { { MPI_ERRORS_ARE_FATAL, 0}, 117 { MPI_ERRORS_RETURN, 0} }; 117 { MPI_ERRORS_RETURN, 0}, 118 { MPI_ERRORS_THROW_EXCEPTIONS, 0} }; 118 119 MPID_Errhandler MPID_Errhandler_direct[MPID_ERRHANDLER_PREALLOC] = { {0} }; 119 120 MPIU_Object_alloc_t MPID_Errhandler_mem = { 0, 0, 0, 0, MPID_ERRHANDLER, -
mpich2/trunk/test/mpi/errors/cxx/errhan/throwtest.cxx
r781 r850 13 13 /* #define VERBOSE */ 14 14 15 /* returns number of errors found */ 16 template <class T> 17 int testCallErrhandler(T &obj, int errorClass, int errorCode, std::string errorString) 18 { 19 int errs = 0; 20 21 try { 22 obj.Call_errhandler(errorCode); 23 std::cerr << "Do Not See This" << std::endl; 24 errs++; 25 } 26 catch (MPI::Exception &ex) { 27 #ifdef VERBOSE 28 std::cerr << "MPI Exception: " << ex.Get_error_string() << std::endl; 29 #endif 30 if (ex.Get_error_code() != errorCode) { 31 std::cout << "errorCode does not match" << std::endl; 32 errs++; 33 } 34 if (ex.Get_error_class() != errorClass) { 35 std::cout << "errorClass does not match" << std::endl; 36 errs++; 37 } 38 if (ex.Get_error_string() != errorString) { 39 std::cout << "errorString does not match" << std::endl; 40 errs++; 41 } 42 } 43 catch (...) { 44 std::cerr << "Caught Unknown Exception" << std::endl; 45 errs++; 46 } 47 48 return errs; 49 } 50 15 51 int main( int argc, char *argv[] ) 16 52 { 17 53 int errs = 0; 18 54 MPI::Win win = MPI::WIN_NULL; 55 MPI::File file = MPI::FILE_NULL; 56 19 57 MPI::Init(); 20 58 … … 23 61 int errorClass = MPI::Add_error_class(); 24 62 int errorCode = MPI::Add_error_code(errorClass); 25 MPI::Add_error_string(errorCode, "Internal-use Error Code"); 63 std::string errorString = "Internal-use Error Code"; 64 MPI::Add_error_string(errorCode, errorString.c_str()); 65 66 win = MPI::Win::Create(NULL, 0, 1, MPI::INFO_NULL, MPI_COMM_WORLD); 67 file = MPI::File::Open(MPI::COMM_WORLD, "testfile", MPI::MODE_WRONLY | MPI::MODE_CREATE | MPI::MODE_DELETE_ON_CLOSE, MPI::INFO_NULL); 26 68 27 69 MPI::COMM_WORLD.Set_errhandler(MPI::ERRORS_THROW_EXCEPTIONS); 28 29 try { 30 if (rank == 0) { 31 MPI::COMM_WORLD.Call_errhandler(errorCode); 32 std::cerr << "Do Not See This\n"; 33 errs++; 34 } 35 } 36 catch (MPI::Exception ex) { 37 #ifdef VERBOSE 38 std::cerr << "MPI Exception: " << ex.Get_error_string() << std::endl; 39 #endif 40 } 41 catch (...) { 42 std::cerr << "Caught Unknown Exception\n"; 43 errs++; 70 win.Set_errhandler(MPI::ERRORS_THROW_EXCEPTIONS); 71 file.Set_errhandler(MPI::ERRORS_THROW_EXCEPTIONS); 72 73 if (0 == rank) { 74 errs += testCallErrhandler(MPI::COMM_WORLD, errorClass, errorCode, errorString); 75 errs += testCallErrhandler(win, errorClass, errorCode, errorString); 76 errs += testCallErrhandler(file, errorClass, errorCode, errorString); 44 77 } 45 78 46 79 if (errs == 0) { 47 std::cout << " No Errors" << std::endl;80 std::cout << " No Errors" << std::endl; 48 81 } 49 82 else { 50 std::cout << " Found " << errs << " errors" << std::endl;83 std::cout << " Found " << errs << " errors" << std::endl; 51 84 } 52 85
