Skip to content

Commit 06c5636

Browse files
committed
Add a test for mpi_errors_mpi3 behavior and non-catastrophic errors
Signed-off-by: Aurelien Bouteiller <bouteill@icl.utk.edu>
1 parent b37202c commit 06c5636

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

test/simple/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PROGS = mpi_no_op mpi_barrier hello hello_nodename abort multi_abort comm_abort initial_errh simple_spawn \
22
concurrent_spawn spawn_multiple mpi_spin delayed_abort loop_spawn loop_child \
3-
bad_exit pubsub hello_barrier segv accept connect hello_output hello_show_help \
3+
bad_exit bad_arg pubsub hello_barrier segv accept connect hello_output hello_show_help \
44
crisscross read_write ziatest slave reduce-hang ziaprobe ziatest bcast_loop \
55
parallel_w8 parallel_w64 parallel_r8 parallel_r64 sio sendrecv_blaster early_abort \
66
debugger singleton_client_server intercomm_create spawn_tree init-exit77 mpi_info \

test/simple/bad_arg.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2020 The University of Tennessee and The University
3+
* of Tennessee Research Foundation. All rights
4+
* reserved.
5+
* $COPYRIGHT$
6+
*
7+
* Additional copyrights may follow
8+
*
9+
* $HEADER$
10+
*/
11+
12+
#include <stdio.h>
13+
#include <unistd.h>
14+
#include "mpi.h"
15+
16+
void errhandler(MPI_Comm* comm, int* err) {
17+
int rank, len = 0;
18+
char errstr[MPI_MAX_ERROR_STRING] = {0};
19+
char cname[MPI_MAX_OBJECT_NAME] = {0};
20+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
21+
MPI_Error_string(*err, errstr, &len);
22+
MPI_Comm_get_name(*comm, cname, &len);
23+
fprintf(stderr, "Rank %02d: The error handler for %s has been invoked with error %d: %s\n\n", rank, cname, *err, errstr);
24+
}
25+
26+
27+
28+
int main(int argc, char *argv[])
29+
{
30+
int rank, size, i = 5;
31+
MPI_Errhandler errh;
32+
33+
MPI_Init(&argc, &argv);
34+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
35+
MPI_Comm_size(MPI_COMM_WORLD, &size);
36+
37+
MPI_Comm_create_errhandler(errhandler, &errh);
38+
MPI_Comm_set_errhandler(MPI_COMM_WORLD, errh);
39+
MPI_Comm_set_errhandler(MPI_COMM_SELF, errh);
40+
41+
if(0 == rank) {
42+
fprintf(stderr,
43+
"This test will have rank 1 pass an invalid argument to a local MPI call.\n"
44+
"An error handler has been set, so:\n"
45+
" * A high quality implementation should refrain from calling MPI_ERRORS_ARE_FATAL.\n"
46+
" * An MPI-4 compliant implementation should trigger the MPI_COMM_SELF error handler.\n"
47+
" * An MPI-3 compliant implementation should trigger the MPI_COMM_WORLD error handler.\n\n");
48+
}
49+
50+
sleep(1);
51+
52+
if(1 == rank) {
53+
MPI_Type_set_name(MPI_DATATYPE_NULL, "bad type argument");
54+
}
55+
else {
56+
MPI_Type_set_name(MPI_INT, "good type argument");
57+
}
58+
/* The reported error was not 'important' so we expect MPI to remain
59+
* operative */
60+
61+
/* progress for some time to see if some error handler gets called */
62+
while(i-- > 0) {
63+
MPI_Sendrecv_replace(&size, 1, MPI_INT, 0, 0, 0, 0, MPI_COMM_SELF, MPI_STATUS_IGNORE);
64+
sleep(1);
65+
if(0 == rank) fprintf(stderr, "\rWaiting for %2ds", i);
66+
}
67+
if(0 == rank) fprintf(stderr, "\n");
68+
69+
70+
MPI_Barrier(MPI_COMM_WORLD);
71+
fprintf(stderr, "Rank %02d: I have survived till the end of the test.\n", rank);
72+
73+
MPI_Finalize();
74+
return 0;
75+
}
76+

0 commit comments

Comments
 (0)