Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is MPI_Comm_create_errhandler?

Adnan Abbas

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

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.

Paraller processing

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

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

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;
}
MPI_Comm_create_errhandler
  • 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 the call counter variable.
  • Then, we make the MPI_Comm_create_errhandler call in line 30, providing it the new handler’s user-defined function and address.

RELATED TAGS

c

CONTRIBUTOR

Adnan Abbas
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring