|
| 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