7 int Test_errorhandling (void);
8 /* This is complicated by the fact that not all systems correctly
9 implement stdargs (for the ...) declarations). MPICH uses USE_STDARG
10 as the choice here, instead of the cases
11 if defined(__STDC__) || defined(__cplusplus) || defined(HAVE_PROTOTYPES)
13 #if defined(USE_STDARG)
14 void handler_a( MPI_Comm *, int *, ...);
15 void handler_b( MPI_Comm *, int *, ...);
16 void error_handler(MPI_Comm *, int *, ...);
18 void handler_a ( MPI_Comm *, int * );
19 void handler_b ( MPI_Comm *, int * );
20 void error_handler ( MPI_Comm *, int * );
24 Test the error handers (based on a Fortran test program)
26 int main( int argc, char **argv )
28 MPI_Init( &argc, &argv );
37 static int a_errors, b_errors;
39 int Test_errorhandling( void )
41 char errstring[MPI_MAX_ERROR_STRING];
42 MPI_Comm dup_comm_world, dummy;
44 MPI_Errhandler errhandler_a, errhandler_b, errhandler, old_handler;
45 int err, world_rank, class, resultlen;
48 logical test_default, test_abort
51 MPI_Comm_rank( MPI_COMM_WORLD, &world_rank );
52 MPI_Comm_dup( MPI_COMM_WORLD, &dup_comm_world );
54 if (world_rank == 0 && verbose) {
55 printf( "*** Error Handling ***\n" );
59 Exercise save/restore of user error handlers.
62 MPI_Errhandler_create(handler_a, &errhandler_a);
64 MPI_Errhandler_set(dup_comm_world, errhandler_a);
65 MPI_Errhandler_free(&errhandler_a);
67 if (verbose) printf( "create with null group 1\n" );
68 MPI_Comm_create(dup_comm_world, MPI_GROUP_NULL, &dummy);
70 Test_Failed( " error handler A not invoked\n" );
74 MPI_Errhandler_create(handler_b, &errhandler_b);
75 MPI_Errhandler_get(dup_comm_world, &old_handler);
76 /* The following is needed to preserve an old handler */
77 MPI_Comm_dup( MPI_COMM_SELF, &tempcomm );
78 MPI_Errhandler_set( tempcomm, old_handler );
79 MPI_Errhandler_set(dup_comm_world, errhandler_b);
80 MPI_Errhandler_free(&errhandler_b);
81 if (verbose) printf( "create with null group 2\n" );
82 MPI_Comm_create(dup_comm_world, MPI_GROUP_NULL, &dummy);
84 Test_Failed( " error handler B not invoked\n" );
88 MPI_Errhandler_set(dup_comm_world, old_handler);
89 MPI_Comm_free( &tempcomm );
90 /* MPI_Errhandler_free(&old_handler); */
91 if (verbose) printf( "create with null group 3\n" );
92 MPI_Comm_create(dup_comm_world, MPI_GROUP_NULL, &dummy);
94 Test_Failed( " error handler A not re-invoked\n" );
98 Exercise class & string interrogation.
100 MPI_Errhandler_set(dup_comm_world, MPI_ERRORS_ARE_FATAL);
103 printf( " Three error messages (from two errors) are expected\n\
104 which should both show an error class of %d\n", MPI_ERR_GROUP );
106 MPI_Errhandler_set(dup_comm_world, MPI_ERRORS_RETURN);
107 if (verbose) printf( "create with null group 4\n" );
108 err = MPI_Comm_create(dup_comm_world, MPI_GROUP_NULL, &dummy);
109 if (err != MPI_SUCCESS) {
110 MPI_Error_class(err, &class);
111 MPI_Error_string(err, errstring, &resultlen);
113 printf( "(first) %d : %s\n", class, errstring );
114 else if (class != MPI_ERR_GROUP) {
115 Test_Failed( "(first) Class is not MPI_ERR_GROUP\n" );
120 MPI_Comm_free( &dummy );
121 Test_Failed( "Did not detect error when building communicator\n" );
124 MPI_Errhandler_create(error_handler, &errhandler);
125 MPI_Errhandler_set(dup_comm_world, errhandler);
126 MPI_Errhandler_free(&errhandler);
127 if (verbose) printf( "create with null group 5\n" );
128 err = MPI_Comm_create(dup_comm_world, MPI_GROUP_NULL, &dummy);
129 if (err != MPI_SUCCESS) {
130 MPI_Error_class(err, &class);
131 MPI_Error_string(err, errstring, &resultlen);
133 printf( "(second) %d : %s\n", class, errstring );
134 else if (class != MPI_ERR_GROUP) {
135 Test_Failed( "(second) class was not MPI_ERR_GROUP" );
140 MPI_Comm_free( &dummy );
141 Test_Failed( "Did not detect error in building communicator\n" );
144 MPI_Errhandler_set(dup_comm_world, MPI_ERRORS_ARE_FATAL);
148 printf("Forcing error for default handler...\n");
149 MPI_Comm_create(dup_comm_world, MPI_GROUP_NULL, &dummy);
152 printf( "Calling MPI_Abort...\n" );
153 MPI_Abort(MPI_COMM_WORLD, 123456768);
157 MPI_Comm_free( &dup_comm_world );
160 errs = global_errors;
161 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
162 if (world_rank == 0) {
164 printf( " No Errors\n" );
166 printf( " Found %d errors\n", toterrs );
175 Trivial error handler. Note that FORTRAN error handlers can't
176 deal with the varargs stuff the C handlers can.
179 #if defined(USE_STDARG)
180 void error_handler(MPI_Comm *comm, int *err, ...)
182 void error_handler(MPI_Comm *comm, int *err)
187 char string[MPI_MAX_ERROR_STRING];
189 MPI_Error_class(*err, &class);
190 MPI_Error_string(*err, string, &resultlen);
192 printf( "(errhandler) %d : %s\n", class, string );
194 if (class != MPI_ERR_GROUP) {
195 printf( "(errhandler) class = %d, expected %d (MPI_ERR_GROUP)\n",
196 class, MPI_ERR_GROUP );
197 printf( " message %s\n", string );
203 Error handler A, used for save/restore testing.
206 #if defined(USE_STDARG)
207 void handler_a( MPI_Comm *comm, int *err, ...)
209 void handler_a(MPI_Comm *comm, int err)
214 MPI_Error_class(*err, &class);
215 if (class != MPI_ERR_GROUP) {
216 printf( "handler_a: incorrect error class %d\n", class );
223 Error handler B, used for save/restore testing.
226 #if defined(USE_STDARG)
227 void handler_b(MPI_Comm *comm, int *err, ...)
229 void handler_b(comm, err)
236 MPI_Error_class(*err, &class);
237 if (class != MPI_ERR_GROUP) {
238 printf( "handler_b: incorrect error class %d\n", class );