MPI (Message Passing Interface) is a library that allows you to write parallel programs in C or Fortran77. The library uses commonly available operating system services to create parallel processes and exchange information among these processes.
This method creates a communicator error handler.
int MPI_Comm_create_errhandler(MPI_Comm_errhandler_function *comm_errhandler_fn, MPI_Errhandler *errhandler)
comm_errhandler_function
is a user-defined error handling function of the form void MPI_Comm_errhandler_function(MPI_Comm *comm, int *rc);
.
errorhandler
is an output parameter representing the MPI error handler.
The function returns an error if it is unsuccessful. The error aborts the MPI job by default.
In case of success, it returns MPI_SUCCESS
- the value returned upon successful termination of any MPI routine.
In case of an invalid communicator provided in the function’s argument, MPI_ERR_COM
is returned.
MPI_ERR_OTHER
is returned if there is some other error. You can use MPI_Error_string
to get more information about this error code.
The example below demonstrates how we can use the MPI_Comm_create_errhandler
method:
#include "mpi.h"#include <stdio.h>static int calls = 0;static int errs = 0;static MPI_Comm mycomm;void userDefinedErrHandler( MPI_Comm *comm, int *err, ... ){if (*err != MPI_ERR_OTHER) {errs++;printf( "Unexpected error code\n" );fflush(stdout);}if (*comm != mycomm) {errs++;printf( "Unexpected communicator\n" );fflush(stdout);}calls++;return;}int main( int argc, char *argv[] ){MPI_Comm comm;MPI_Errhandler newHandler;MPI_Init( &argc, &argv );comm = MPI_COMM_WORLD;mycomm = comm;MPI_Comm_create_errhandler( userDefinedErrHandler, &newHandler );return 0;}
userDefinedErrorHandler
. The handler checks if the call returned an error code or the communicator was not original. After these checks, it simply increments the call
counter variable.MPI_Comm_create_errhandler
call in line 30, providing it the new handler’s user-defined function and address.