PetscUnlikelyDebug#

Hints the compiler that the given condition is usually false, eliding the check in optimized mode

Synopsis#

#include <petscmacros.h>
bool PetscUnlikelyDebug(bool cond)

Not Collective

Input Parameters#

  • cond - Boolean expression

Notes#

Not available from Fortran, requires variadic macro support, definition is disabled by defining PETSC_SKIP_VARIADIC_MACROS.

This returns the same truth value, it is only a hint to compilers that the result of cond is likely to be false. When PETSc is compiled in optimized mode this will always return false. Additionally, cond is guaranteed to not be evaluated when PETSc is compiled in optimized mode.

Example usage#

This routine is shorthand for checking both the condition and whether PetscDefined(USE_DEBUG) is true. So

  if (PetscUnlikelyDebug(cond)) {
    foo();
  } else {
    bar();
  }

is equivalent to

  if (PetscDefined(USE_DEBUG)) {
    if (PetscUnlikely(cond)) {
      foo();
    } else {
      bar();
    }
  } else {
    bar();
  }

See Also#

PetscUnlikely(), PetscLikely(), PetscCall(), SETERRQ

Level#

advanced

Location#

include/petscmacros.h


Edit on GitLab

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