PetscAssert — PETSc 3.22.5 documentation

Skip to main content
`Ctrl`+`K`

# PetscAssert

Assert that a particular condition is true

## Synopsis

    #include <petscerror.h>
    void PetscAssert(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...)

Collective; No Fortran Support

## Input Parameters

- cond - The boolean condition

- comm - The communicator on which the check can be collective on

- ierr - A nonzero error code, see include/petscerror.h for the complete list

- message - Error message in `printf()` format

## Notes

Equivalent to `PetscCheck()` if debugging is enabled, and `PetscAssume(cond)` otherwise.

See `PetscCheck()` for usage and behaviour.

This is needed instead of simply using `assert()` because this correctly handles the collective nature of errors under MPI

## See Also

`PetscCheck()`, `SETERRQ()`, `PetscError()`, `PetscAssertAbort()`, `PetscErrorCode`

## Level

beginner

## Location

include/petscerror.h

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