[petsc-dev] PETSC_VIEWER_FAILED
Pierre Jolivet
pierre at joliv.et
Wed Feb 8 01:39:11 CST 2023
Hello,
There is not much code around using PETSC_VIEWER_FAILED, and I don’t understand the following behavior.
diff --git a/src/ksp/ksp/tutorials/ex1.c b/src/ksp/ksp/tutorials/ex1.c
index 702467ebd51..708a2ff8c9a 100644
--- a/src/ksp/ksp/tutorials/ex1.c
+++ b/src/ksp/ksp/tutorials/ex1.c
@@ -147,3 +147,5 @@ int main(int argc, char **args)
PetscCall(MatShift(A, 2.0));
+ PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)ksp)), PETSC_VIEWER_FAILED));
PetscCall(KSPSolve(ksp, b, x));
+ PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)ksp))));
$ ./ex1 -ksp_converged_reason
Linear solve converged due to CONVERGED_RTOL iterations 5
[…]
Linear solve converged due to CONVERGED_RTOL iterations 5
How do I get the second solve to remain silent _unless_ there is a failure?
Why is the code not doing what the documentation is stating, i.e., “use PETSC_VIEWER_FAILED to only display a reason if it fails” (maybe because the KSP has its own viewer but how do I retrieve it in a user-code)?
Thanks,
Piere
More information about the petsc-dev
mailing list