[petsc-dev] handling user domain errors

Barry Smith bsmith at mcs.anl.gov
Mon Apr 20 18:23:22 CDT 2015


  Dmitry,

   Rather than introducing another whole complexity of flags for indicating domain errors in user functions just do the following.

   1) just stick a Nan into the functions result
   2) remove the VecValidValues() at the END of routines like MatMult()
   3) when Nan or Inf pop up in Krylov methods (which will happen within VecNorm or VecDot() and thus we get free collective knowledge of the problem even if it happened on only one node), generate the appropriate KSP_DIVERGED_NANORINF. This is already handled sometimes (most of the time?), for example in KSPSolve_CG is code
ierr = VecXDot(Z,R,&beta);CHKERRQ(ierr);         /*  beta <- z'*r       */
    if (PetscIsInfOrNanScalar(beta)) {
      if (ksp->errorifnotconverged) SETERRQ(PetscObjectComm((PetscObject)ksp),PETSC_ERR_NOT_CONVERGED,"KSPSolve has not converged due to Nan or Inf inner product");
      else {
        ksp->reason = KSP_DIVERGED_NANORINF;
        PetscFunctionReturn(0);
      }
    }

   4) SNES already handles failed to converge KSP and
   5 ) TS already handles failed to converged SNES; by, for example, cutting the timestep.

  Barry





More information about the petsc-dev mailing list