1 /* 2 * Copyright (C) by Argonne National Laboratory 3 * See COPYRIGHT in top-level directory 4 */ 5 6 #include "mpitestconf.h" 7 #include "mpi.h" 8 #ifdef HAVE_IOSTREAM 9 // Not all C++ compilers have iostream instead of iostream.h 10 #include <iostream> 11 #ifdef HAVE_NAMESPACE_STD 12 // Those that do often need the std namespace; otherwise, a bare "cout" 13 // is likely to fail to compile 14 using namespace std; 15 #endif 16 #else 17 #include <iostream.h> 18 #endif 19 20 #ifdef HAVE_STRING_H 21 #include <string.h> 22 #endif 23 #include "mpitestcxx.h" 24 25 static int ncalls = 0; efn(MPI::Comm & comm,int * code,...)26void efn(MPI::Comm & comm, int *code, ...) 27 { 28 ncalls++; 29 } 30 main(int argc,char * argv[])31int main(int argc, char *argv[]) 32 { 33 MPI::Errhandler eh; 34 int size; 35 bool foundMsg; 36 int errs = 0; 37 38 MTest_Init(); 39 40 size = MPI::COMM_WORLD.Get_size(); 41 42 // Test that we can change the default error handler to not throw 43 // an exception (our error handler could also throw an exception, 44 // but we want to make sure that the exception is not thrown 45 // by the MPI code) 46 47 eh = MPI::Comm::Create_errhandler(efn); 48 MPI::COMM_WORLD.Set_errhandler(eh); 49 try { 50 foundMsg = MPI::COMM_WORLD.Iprobe(size, 0); 51 } catch(MPI::Exception ex) { 52 cout << "Caught exception from iprobe (should have called error handler instead)\n"; 53 errs++; 54 if (ex.Get_error_class() == MPI_SUCCESS) { 55 errs++; 56 cout << "Unexpected error from Iprobe" << endl; 57 } 58 } 59 if (ncalls != 1) { 60 errs++; 61 cout << "Did not invoke error handler when invoking iprobe with an invalid rank" << endl; 62 } 63 64 eh.Free(); 65 66 // Find out how many errors we saw 67 68 MTest_Finalize(errs); 69 70 return 0; 71 } 72