Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the PETSc TS interfaces conform to callback conventions. #15269

Merged
merged 5 commits into from May 28, 2023

Conversation

bangerth
Copy link
Member

@stefanozampini I would love it if you could take a look over this.

On my workstation, this currently fails with an exception of this form:

11719: 5.9375 -0.344285 (-0.338842) 0.937523 (0.940843)
11719: 6 -0.285132 (-0.279415) 0.957169 (0.96017)
11719: # Number of steps taken: 80
11719: # Test explicit interface (J 1)
11719: 1 0.841471 (0.841471) 0.540302 (0.540302)
11719: 
11719: petsc/petsc_ts_00.debug: RUN failed. ------ Additional output on stdout/stderr:
11719: 
11719: [0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
11719: [0]PETSC ERROR: Object is in wrong state
11719: [0]PETSC ERROR: Not for unassembled matrix
11719: [0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.
11719: [0]PETSC ERROR: Petsc Release Version 3.7.4, Oct, 02, 2016 
11719: [0]PETSC ERROR: /home/fac/g/bangerth/p/deal.II/1/build/tests/petsc/petsc_ts_00.debug/petsc_ts_00.debug on a x86_64 named strange.math.colostate.edu by bangerth Wed May 24 17:34:28 2023
11719: [0]PETSC ERROR: Configure options --with-shared-libraries=1 --with-x=0 --with-mpi=1 --download-hypre=1 --download-superlu_dist=yes --download-mumps=yes --download-parmetis=yes --download-scalapack=yes --download-metis=yes --download-blacs=yes
11719: [0]PETSC ERROR: #1 MatDuplicate() line 4335 in /raid/bangerth/bin/petsc-3.7.4/src/mat/interface/matrix.c
11719: [0]PETSC ERROR: #2 TSGetRHSMats_Private() line 751 in /raid/bangerth/bin/petsc-3.7.4/src/ts/interface/ts.c
11719: [0]PETSC ERROR: #3 TSComputeIJacobian() line 929 in /raid/bangerth/bin/petsc-3.7.4/src/ts/interface/ts.c
11719: [0]PETSC ERROR: #4 SNESTSFormJacobian_BDF() line 324 in /raid/bangerth/bin/petsc-3.7.4/src/ts/impls/bdf/bdf.c
11719: [0]PETSC ERROR: #5 SNESTSFormJacobian() line 5015 in /raid/bangerth/bin/petsc-3.7.4/src/ts/interface/ts.c
11719: [0]PETSC ERROR: #6 SNESComputeJacobian() line 2312 in /raid/bangerth/bin/petsc-3.7.4/src/snes/interface/snes.c
11719: [0]PETSC ERROR: #7 SNESSolve_NEWTONLS() line 228 in /raid/bangerth/bin/petsc-3.7.4/src/snes/impls/ls/ls.c
11719: [0]PETSC ERROR: #8 SNESSolve() line 4005 in /raid/bangerth/bin/petsc-3.7.4/src/snes/interface/snes.c
11719: [0]PETSC ERROR: #9 TS_SNESSolve() line 160 in /raid/bangerth/bin/petsc-3.7.4/src/ts/impls/bdf/bdf.c
11719: [0]PETSC ERROR: #10 TSBDF_Restart() line 181 in /raid/bangerth/bin/petsc-3.7.4/src/ts/impls/bdf/bdf.c
11719: [0]PETSC ERROR: #11 TSStep_BDF() line 216 in /raid/bangerth/bin/petsc-3.7.4/src/ts/impls/bdf/bdf.c
11719: [0]PETSC ERROR: #12 TSStep() line 3733 in /raid/bangerth/bin/petsc-3.7.4/src/ts/interface/ts.c
11719: [0]PETSC ERROR: #13 TSSolve() line 3982 in /raid/bangerth/bin/petsc-3.7.4/src/ts/interface/ts.c
11719: terminate called after throwing an instance of 'dealii::LACExceptions::ExcPETScError'
11719:   what():  
11719: --------------------------------------------------------
11719: An error occurred in line <587> of file </home/fac/g/bangerth/p/deal.II/1/dealii/include/deal.II/lac/petsc_ts.templates.h> in function
11719:     unsigned int dealii::PETScWrappers::TimeStepper<VectorType, PMatrixType, AMatrixType>::solve(VectorType&) [with VectorType = dealii::PETScWrappers::MPI::Vector; PMatrixType = dealii::PETScWrappers::MatrixBase; AMatrixType = dealii::PETScWrappers::MatrixBase]
11719: The violated condition was: 
11719:     ierr == 0
11719: Additional information: 
11719:     deal.II encountered an error while calling a PETSc function.
11719:     The description of the error provided by PETSc is "Object is in wrong
11719:     state".
11719:     The numerical value of the original error code is 73.
11719: --------------------------------------------------------

I have to run, and so have not investigated what may be going wrong. I also don't know whether I have run these tests on this machine before, so am only half-certain that this is caused by the current patch.

In reference to #15112.

@bangerth bangerth added this to the Release 9.5 milestone May 24, 2023
@bangerth
Copy link
Member Author

For reference, this is the petsc/petsc_ts_00 test. The _01 and _02 tests work as expected.

@bangerth
Copy link
Member Author

The error appears to be a problem on the system on which I ran this. The tester is ok, and so is my laptop. In other words, this is good to review.

@bangerth
Copy link
Member Author

I verified that this must be an issue with the rather old PETSc version on that machine, and that the failure predates the patch.

I've also pushed more commits that add tests, including one that verifies that, unlike SUNDIALS, PETSc TS is unable to deal with recoverable errors in user callbacks.

@stefanozampini
Copy link
Contributor

stefanozampini commented May 26, 2023

I can extend the code to support recoverable errors. Regarding the failures, deal.ii now requires petsc 3.8 or later
@bangerth Can you check it works with 3.8?

@stefanozampini
Copy link
Contributor

I have modified the call_and_possibly function to eat the exception as for the sundials case. On second thought, I think it is better to return and re-raise it so that the outer try and catch around SNESSolve will deal with it. Your call

@bangerth
Copy link
Member Author

Same here: Can I ask for this patch to be merged without @stefanozampini 's addition? It tests cleanly and is self-contained. I will take care of the changes @stefanozampini suggests in a separate patch.

@stefanozampini
Copy link
Contributor

Same here: Can I ask for this patch to be merged without @stefanozampini 's addition? It tests cleanly and is self-contained. I will take care of the changes @stefanozampini suggests in a separate patch.

Fine with me. It appears TS errors are not recoverable yet (I will try to look at this in PETSc) but SNES are (at least in function evaluation). See here #15276

@luca-heltai luca-heltai merged commit 862fc97 into dealii:master May 28, 2023
14 checks passed
@bangerth bangerth deleted the petsc-ts branch May 30, 2023 20:44
@kronbichler
Copy link
Member

For the unity build of deal.II, this PR (or the companion #15271) lead to build errors, see e.g. https://cdash.dealii.org/viewBuildError.php?buildid=1027 because we have the two functions with the same name and arguments

template <typename F, typename... Args>
int
call_and_possibly_capture_exception(const F & f,
std::exception_ptr &eptr,
Args &&...args)
{
and
template <typename F, typename... Args>
int
call_and_possibly_capture_exception(const F & f,
std::exception_ptr &eptr,
Args &&...args)
{
that both get included in the same compilation unit. It would make sense to avoid the duplication anyway. @bangerth could you please take a look?

@masterleinad
Copy link
Member

@kronbichler #15284 provides a quick fix.

@kronbichler
Copy link
Member

Yes, I saw it only now. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants