PetscCheck#

Checks that a particular condition is true; if not true, then returns the provided error code

Synopsis#

#include <petscsys.h>
void PetscCheck(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 the printf() format

Notes#

Enabled in both optimized and debug builds.

As a general rule, PetscCheck() is used to check “usage error” (for example, passing an incorrect value as a function argument), PetscAssert() is used to “check for bugs in PETSc” (for example, is a value in a PETSc data structure nonsensical). However, for functions that are called in a “hot spot”, for example, thousands of times in a loop, PetscAssert() should be used instead of PetscCheck() since the former is compiled out in PETSc’s optimization code.

Calls SETERRQ() if the assertion fails, so can only be called from functions returning a PetscErrorCode (or equivalent type after conversion).

See Also#

PetscAssert(), PetscCheckReturnMPI(), SETERRQ(), PetscError(), PetscCall(), PetscCheckAbort(), PetscErrorCode

Level#

beginner

Location#

include/petscerror.h

Examples#

src/sys/classes/random/tutorials/ex1.c
src/sys/classes/random/tutorials/ex2.c
src/sys/tutorials/ex17.c
src/sys/tutorials/ex20.c
src/sys/tutorials/ex3.c
src/sys/classes/random/tests/ex3.c
src/sys/classes/viewer/tests/ex5.c
src/sys/classes/viewer/tests/ex6.c
src/sys/classes/viewer/tests/ex8.c
src/sys/objects/device/tests/ex1.c


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