What is MPI_Comm_create_errhandler?
MPI library
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.
MPI_Comm_ceate_errhandler
This method creates a communicator error handler.
Syntax
int MPI_Comm_create_errhandler(MPI_Comm_errhandler_function *comm_errhandler_fn, MPI_Errhandler *errhandler)
Parameters
-
comm_errhandler_functionis a user-defined error handling function of the formvoid MPI_Comm_errhandler_function(MPI_Comm *comm, int *rc);. -
errorhandleris an output parameter representing the MPI error handler.
Return value
-
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_COMis returned. -
MPI_ERR_OTHERis returned if there is some other error. You can useMPI_Error_stringto get more information about this error code.
Example
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;}
- We create our error handling function defined in line 8 as
userDefinedErrorHandler. The handler checks if the call returned an error code or the communicator was not original. After these checks, it simply increments thecallcounter variable. - Then, we make the
MPI_Comm_create_errhandlercall in line 30, providing it the new handler’s user-defined function and address.
Free Resources