:orphan:
# PetscCallMPI
Checks error code returned from MPI calls, if non-zero it calls the error handler and then returns 
## 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
```none
  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
```none
  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()`, `SETERRQ()`, `SETERRABORT()`, `PetscCallAbort()`,
`PetscCallMPIAbort()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`,
`PetscError()`, `CHKMEMQ`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscerror.h.html#PetscCallMPI">include/petscerror.h</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/tutorials/ex14.c.html">src/dm/impls/plex/tutorials/ex14.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/tutorials/ex5.c.html">src/dm/impls/plex/tutorials/ex5.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/stag/tutorials/ex4.c.html">src/dm/impls/stag/tutorials/ex4.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex1.c.html">src/dm/tutorials/ex1.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex14.c.html">src/dm/tutorials/ex14.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex15.c.html">src/dm/tutorials/ex15.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex20.c.html">src/dm/tutorials/ex20.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex22.c.html">src/dm/tutorials/ex22.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex25.c.html">src/dm/tutorials/ex25.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex51.c.html">src/dm/tutorials/ex51.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex7.c.html">src/dm/tutorials/ex7.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/include/petscerror.h)


[Index of all Sys routines](index.md)  
[Table of Contents for all manual pages](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
