What is MPI_Add_error_class?

MPI library

MPI, short for Message Passing Interface, is a library that allows you to write parallel programs in Fortran77 or C. The library uses common operating system services to exchange information among the parallel processes it creates.

Parallel processing

MPI_Add_error_class

Some users may want to create additional libraries on top of an existing MPI implementation, and these libraries may have their own sets of error codes and classes. For this purpose, MPI offers the MPI_Add_error_class function to create a new error class and return the value for it.

The value is set by the MPI implementation, and not by the user, in order to avoid conflicts with existing error codes and classes.

Syntax

int MPI_Add_error_class(int *errorclass)

Parameters

  • errorclass is an output parameter representing the value for the new error class.

Return value

If unsuccessful, the function returns an error. The error aborts the MPI job by default.

  • In case of success, MPI_Add_error_class returns MPI_SUCCESS, the value returned upon successful termination of any MPI routine.

  • In case of other errors, MPI_ERR_OTHER is returned. MPI_Error_string can be used to get more information about this error code.

Example

The example below shows how we can use the MPI_Add_error_class function to introduce custom error classes in an MPI implementation:

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Create NCLASSES new classes, each with 4 codes (120 total) */
#define NCLASSES 30
#define NCODES 4
int main( int argc, char *argv[] )
{
int newclass[NCLASSES], newcode[NCLASSES][NCODES];
int i, j;
MPI_Init( &argc, &argv );
/* Initialize the new codes */
for (i=0; i<NCLASSES; i++) {
MPI_Add_error_class( &newclass[i] );
for (j=0; j<NCODES; j++) {
MPI_Add_error_code( newclass[i], &newcode[i][j] );
}
}
}
  • We define the macros NCLASSES and NCODES to define the number of classes and the error codes within each class (lines 7-8).
  • We then initialize the newcode and newclass arrays to represent the error classes and their codes (line 12).
  • In the for loop, we use the MPI_Add_error_class method to create a new error class, and within the loop, we also assign each class with its error codes using the MPI_Add_error_code method (line 18, 20).
Copyright ©2024 Educative, Inc. All rights reserved