PetscCall#

Calls a PETSc function and then checks the resulting error code, if it is non-zero it calls the error handler and returns from the current function with the error code.

Synopsis#

#include <petscerror.h>
void PetscCall(PetscFunction(args))

Not Collective

Input Parameter#

  • PetscFunction - any PETSc function that returns an error code

Notes#

Once the error handler is called the calling function is then returned from with the given error code. Experienced users can set the error handler with PetscPushErrorHandler().

PetscCall() cannot be used in functions returning a datatype not convertible to PetscErrorCode. For example, PetscCall() may not be used in functions returning void, use PetscCallAbort() or PetscCallVoid() in this case.

Example Usage#

  PetscCall(PetscInitiailize(...)); // OK to call even when PETSc is not yet initialized!

  struct my_struct
  {
    void *data;
  } my_complex_type;

  struct my_struct bar(void)
  {
    PetscCall(foo(15)); // ERROR PetscErrorCode not convertible to struct my_struct!
  }

  PetscCall(bar()) // ERROR input not convertible to PetscErrorCode

It is also possible to call this directly on a PetscErrorCode variable

  PetscCall(ierr);  // check if ierr is nonzero

Should not be used to call callback functions provided by users, PetscCallBack() should be used in that situation.

PetscUseTypeMethod() or PetscTryTypeMethod() should be used when calling functions pointers contained in a PETSc object’s ops array

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 PETSc function being called.

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

Example Fortran Usage#

  PetscErrorCode ierr
  Vec v

  ...
  PetscCall(VecShift(v,1.0,ierr))
  PetscCallA(VecShift(v,1.0,ierr))

See Also#

SETERRQ(), PetscCheck(), PetscAssert(), PetscTraceBackErrorHandler(), PetscCallMPI(), PetscPushErrorHandler(), PetscError(), CHKMEMQ, CHKERRA(), CHKERRMPI(), PetscCallBack(), PetscCallAbort(), PetscCallVoid()

Level#

beginner

Location#

include/petscerror.h

Examples#

src/dm/dt/dualspace/impls/lagrange/tutorials/ex1.c
src/dm/dt/dualspace/impls/lagrange/tutorials/ex2.c
src/dm/field/tutorials/ex1.c
src/dm/impls/forest/tutorials/ex1.c
src/dm/impls/plex/tutorials/ex1.c
src/dm/impls/plex/tutorials/ex10.c
src/dm/impls/plex/tutorials/ex11.c
src/dm/impls/plex/tutorials/ex13.c
src/dm/impls/plex/tutorials/ex14.c
src/dm/impls/plex/tutorials/ex5.c
src/dm/impls/plex/tutorials/ex6.c


Edit on GitLab

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