catching SolverControl::NoConvergence

25 views
Skip to first unread message

Alberto Salvadori

unread,
Jul 29, 2020, 7:37:23 AM7/29/20
to deal.II User Group
Dear community

in these days I am particularly bothering you, I apologize. Today, I wonder if I can receive some clarifications on catching the exception SolverControl::NoConvergence in using trilinos.

I wrote the code below for a linear system solver:

SolverControl bicgstab_solver_control ( bicgstab_max_iterations , tolerance ); 
SolverControl gmres_solver_control ( gmres_max_iterations , tolerance );  


#ifdef USE_PETSC_LA
PETScWrappers::SolverBicgstab bicgstab (bicgstab_solver_control, this->mpi_communicator);
PETScWrappers::SolverGMRES gmres (gmres_solver_control, this->mpi_communicator, PETScWrappers::SolverGMRES::AdditionalData(50, true));

#else
TrilinosWrappers::SolverBicgstab::AdditionalData solver_data;
TrilinosWrappers::SolverBicgstab bicgstab (bicgstab_solver_control, solver_data );
TrilinosWrappers::SolverGMRES gmres (gmres_solver_control, TrilinosWrappers::SolverGMRES::AdditionalData(50, true));

#endif

if ( PreconditionIsAMG )

{

LA::MPI::PreconditionAMG preconditioner;
LA::MPI::PreconditionAMG::AdditionalData data;
preconditioner.initialize(this->system_matrix, data);

try
{
iterate_on_tolerance = false ;
this->pcout << " AMG - Bicgstab " << std::flush ;

bicgstab.solve (this->system_matrix, distributed_incremental_displacement, this->system_rhs, preconditioner);
solver_control_last_step = bicgstab_solver_control.last_step();
}

catch ( SolverControl::NoConvergence )
{
iterate_on_tolerance = true ;
try
{
  ... whatever ...
}

My idea is: whenever  bicgstab.solve fails, for instance because the accuracy is higher than the tolerance, I want to catch the exception SolverControl::NoConvergence  and do something else. I am insecure if the above code is fine for this purpose, could you please address me  to a broader explanation ?
At any rate, it turns out that the code above works OK for PETSc, but not for trilinos - I do would like to use trilinos for the sake of memory leaks. Apparently , errors of kind 

aztec00 error code #

take the lead with trilinos and the exception is not caught properly. I must have done something wrong.

I appreciate your help.

Alberto



Wolfgang Bangerth

unread,
Jul 29, 2020, 8:15:16 PM7/29/20
to dea...@googlegroups.com
On 7/29/20 5:37 AM, Alberto Salvadori wrote:
>
> try
> {
> iterate_on_tolerance = false ;
> this->pcout << " AMG - Bicgstab " << std::flush ;
>
> bicgstab.solve (this->system_matrix, distributed_incremental_displacement,
> this->system_rhs, preconditioner);
> solver_control_last_step = bicgstab_solver_control.last_step();
> }
>
> catch ( SolverControl::NoConvergence )
> {
> iterate_on_tolerance = true ;
> try
> {
>   ... whatever ...
> }
>
> My idea is: whenever  bicgstab.solve fails, for instance because the accuracy
> is higher than the tolerance, I want to catch the exception
> SolverControl::NoConvergence  and do something else. I am insecure if the
> above code is fine for this purpose, could you please address me  to a broader
> explanation ?

Yes, this is the equivalent code of what we have here in ASPECT:
https://github.com/geodynamics/aspect/blob/master/source/simulator/solver.cc#L502-L520
or more tailored to your situation:
https://github.com/geodynamics/aspect/blob/master/source/simulator/solver.cc#L838-L913


> At any rate, it turns out that the code above works OK for PETSc, but not for
> trilinos - I do would like to use trilinos for the sake of memory leaks.
> Apparently , errors of kind
>
> aztec00 error code #
>
> take the lead with trilinos and the exception is not caught properly. I must
> have done something wrong.
Interesting. Can you again construct a small test case so we can see how to
fix this?

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Alberto Salvadori

unread,
Jul 31, 2020, 5:44:41 AM7/31/20
to deal.II User Group
Wolfgang,

I am going to provide the small test case as soon as I can make it. In the meanwhile, it turned out that 

catch ( const std::exception &exc)

rather than  SolverControl::NoConvergence  works fine. 
By the way, I noticed that there is no Trilinos wrapper for GMRES, yet the implementation of LA::MPI::SolverGMRES provides no error when 
the trilinos flag is set. Is there any redirection to another solver? Is this a potential source of the unexpected behavior mentioned above?

Thank you.

Alberto

Wolfgang Bangerth

unread,
Aug 3, 2020, 12:32:26 PM8/3/20
to dea...@googlegroups.com
On 7/31/20 3:44 AM, Alberto Salvadori wrote:
> By the way, I noticed that there is no Trilinos wrapper for GMRES, yet the
> implementation of LA::MPI::SolverGMRES provides no error when
> the trilinos flag is set. Is there any redirection to another solver? Is this
> a potential source of the unexpected behavior mentioned above?

Good question. Can you create a minimal test case for that as well?
Reply all
Reply to author
Forward
0 new messages