Skip to main content
`Ctrl`+`K`

# PetscCallMPI

Checks error code returned from MPI calls, if non-zero it calls the error handler and then returns a `PetscErrorCode`

## Synopsis

    #include <petscerror.h>
    void PetscCallMPI(MPI_Function(args))

Not Collective

## Input Parameter

- MPI_Function - an MPI function that returns an MPI error code

## Notes

Always returns the error code `PETSC_ERR_MPI`; the MPI error code and string are embedded in the string error message. Do not use this to call any other routines (for example PETSc routines), it should only be used for direct MPI calls. The user may configure PETSc with the `--with-strict-petscerrorcode` option to check this at compile-time, otherwise they must check this themselves.

This routine can only be used in functions returning `PetscErrorCode` themselves. If the calling function returns a different type, use `PetscCallMPIAbort()` instead.

## Example Usage

      PetscCallMPI(MPI_Comm_size(...)); // OK, calling MPI function

      PetscCallMPI(PetscFunction(...)); // ERROR, use PetscCall() instead!

## Fortran Notes

The Fortran function from which this is used must declare a variable `PetscErrorCode` ierr and ierr must be the final argument to the MPI function being called.

In the main program and in Fortran subroutines that do not have ierr as the final return parameter one should use `PetscCallMPIA()`

## Fortran Usage

      PetscErrorCode ierr or integer ierr
      ...
      PetscCallMPI(MPI_Comm_size(...,ierr))
      PetscCallMPIA(MPI_Comm_size(...,ierr)) ! Will abort after calling error handler

      PetscCallMPI(MPI_Comm_size(...,eflag)) ! ERROR, final argument must be ierr

## See Also

`SETERRMPI()`, `PetscCall()`, `PetscCallReturnMPI()`, `SETERRQ()`, `SETERRABORT()`, `PetscCallAbort()`, `PetscCallMPIAbort()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ`, `PetscCallMPINull()`

## Level

beginner

## Location

include/petscerror.h

Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages