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

Add SolverDirect for Tpetra Wrappers #16602

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

jpthiele
Copy link
Contributor

@jpthiele jpthiele commented Feb 7, 2024

This will add support for (sparse) direct solvers implemented
or interfaced in Amesos2, which is part of the Tpetra stack.

Status:

Implementation itself (with A as LA::TpetraWrappers::SparseMatrix)

  • Interface for initialize(A)
  • Interface for solve(x,b) with LA::TpetraWrappers::Vector
  • Interface for solve(A,x,b) with LA::TpetraWrappers::Vector
  • Interface for setting Teuchos::ParameterList

include/deal.II/lac/trilinos_tpetra_solver.h Outdated Show resolved Hide resolved
include/deal.II/lac/trilinos_tpetra_solver.h Outdated Show resolved Hide resolved
include/deal.II/lac/trilinos_tpetra_solver.h Outdated Show resolved Hide resolved
@bangerth
Copy link
Member

bangerth commented Feb 7, 2024

Might help with #10414.

Copy link
Member

@bangerth bangerth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll eventually also have to add the .cc and/or .templates.h file.

include/deal.II/lac/trilinos_tpetra_solver.h Outdated Show resolved Hide resolved
include/deal.II/lac/trilinos_tpetra_solver.h Outdated Show resolved Hide resolved
@jpthiele
Copy link
Contributor Author

jpthiele commented Feb 7, 2024

You'll eventually also have to add the .cc and/or .templates.h file.

That file is already in the works.

I also looked at the Epetra tests for the direct solvers but they CG solver of AztecOO as a baseline.
I would suggest using KLU2 and compare it to the solutions of all other solvers that are configured?
Maybe we will also have to configure a test setup for the currently uninstalled solvers.

@jpthiele
Copy link
Contributor Author

jpthiele commented Feb 7, 2024

Might help with #10414.

Yes definitely, there are multiple solvers that were at least not mentioned in the Epetra wrappers but partially also not in Amesos(1).

SuperLU_MT is also wrapped in Amesos2.
As is MKL_Pardiso which has an OpenMP version.
And ShyLU Basker and Tacho which are a shared-memory LU and Cholesky factorizations.

But looking at the documentation of the solver wrapper classes in Amesos2 I see that we should also give the option
to pass a Teuchos::Parameter list, so users can fine tune the solvers should they want to.

@jpthiele jpthiele force-pushed the tpetra-solverdirect branch 2 times, most recently from c24240a to d9af340 Compare February 10, 2024 12:46
@jpthiele jpthiele mentioned this pull request Feb 10, 2024
4 tasks
@jpthiele
Copy link
Contributor Author

Related to #16614 the question remains what the best way to convert a sequential Vector and a distributed Vector from deal.II to Tpetra actually is.
As it is also needed here a specialized function would be great @kinnewig.

@jpthiele
Copy link
Contributor Author

Working on the parameters a question would be whether we want some Utility classes or structs
to handle creation of a valid parameter list for a solver?

Especially for MUMPS a user would have to dig deep to find out what ICNTL(1) or ICNTL(9) would actually set.
Having a simple struct maybe with enums to set things like solving Ax=b vs. A^Tx=b vs. A^*x=b or whether or not a matrix is symmetric would be a lot easier then.

@bangerth
Copy link
Member

We usually do this via AdditionalData structs. That could be used here as well, but I will be ok with just a patch that provides the bare minimum to make things work, and then come back to making it more convenient later on.

I think it would be great if we could make the majority of the tests in #16611 work by the end of April or so, so we can be sure that this can all be shipped with the next release. There will be things we want to improve later on, and making things convenient may fall in this category.

@jpthiele
Copy link
Contributor Author

The additional data would work if there is a nonempty intersection of all possible parameters for the solvers.

Another option would be to write derived classes for each of the supported solvers with their data sets.
But that seems like doubling work as that is already what Amesos2 does basically.

@jpthiele
Copy link
Contributor Author

In terms of staying in one ecosystem, i.e. all TpetraWrappers the SolverDirect wrapper is now feature complete.
All we need is a mapping from dealii::Vector and dealii::LinearAlgebra::distributed::Vector but that could also be done
in a seperate PR.

Considering testing we might think about also testing the float, std::complex<float> and std::complex<double> configurations.

@jpthiele
Copy link
Contributor Author

I just had a look at the Ifpack1 preconditioners in deal.II and noticed that we basically do
exactly what I proposed, i.e. a PreconditionBase that could be used with any ifpack preconditioner given the right parameter set
(and we should probably expose that functionality somewhere) for Ifpack2
and we have derived classes to set the right set of parameters.

So I would propose to actually use the chance of reworking the interface to have the same structure for both.

The structure would be as follows:

  • PreconditionBase and SolverDirectBase
  • derived classes for specific solvers, e.g. PreconditionsSSOR, SolverDirectKLU(2), SolverDirectMUMPS.
  • and a derived class for full customization using the Teuchos::ParameterList, SolverDirect and Precondition

What do you think @bangerth, @kinnewig, @kronbichler, @masterleinad ?

@kronbichler
Copy link
Member

I would be very happy if we could have a class that can be set with parameter files alongside some generic classes that implement often-used options, exactly as you suggest. I think it often is desirable for more complex codes to switch between different options for solvers and preconditioners via a parameter file. Of course, one can address that by adding the necessary switches in the C++ code (via a base class or similar mechanisms) for cases where the code needs different implementations. But since Trilinos/Ifpack2/Amesos2 already does control via a single solver instance that for us, it would be a pity not to use it. So 👍 from my end to this suggestion.

@jpthiele
Copy link
Contributor Author

I have reworked the class layout as discussed.
So now we have a SolverDirectBase that can't be instantiated on its own (protected constructor)
a SolverDirect that works basically like the intermediate implementation by supplying a solver_name
in the AdditionalData field and then optionally passing a Teuchos::ParameterList to fine tune.

Additionally, we have SolverDirektKLU2 which has all the AdditionalData fields that the parameter set provides.

We also have a test 01 to ensure setting a parameter sets works (here with KLU2 again) and to ensure that
the exception is raised when an unsupported solver is about to be created.
And a test 02 to see that KLU2 works.

I have also finished a SolverDirectLAPACK and SolverDirectTachoderived class,
but both fail with some Lapack error

** On entry to DPOTRF parameter number  4 had an illegal value (Tacho)
** On entry to DGEEQU parameter number  4 had an illegal value (Lapack)

but that might possibly stem from some 64bit vs. 32bit clash.
I'd have to recompile Trilinos with 32bit to find out.
If anyone has a setup like that already running you can try to see if you get these errors by passing "Tacho" or "LAPACK" to the SolverDirect class as solver_name

@jpthiele jpthiele marked this pull request as ready for review February 12, 2024 20:12
@jpthiele
Copy link
Contributor Author

I have undrafted it because I feel that any further work like supporting specific solvers could be done in separate PRs.

@jpthiele jpthiele changed the title WIP: Add SolverDirect for Tpetra Wrappers Add SolverDirect for Tpetra Wrappers Feb 12, 2024
@jpthiele
Copy link
Contributor Author

jpthiele commented Feb 13, 2024

Having the same problem with Ifpack2, I just noticed that we should check whether Amesos2 is actually part of Trilinos and added that to the CMake files.
This works, but changing the filenames of the direct tests and inserting trilinos_with_amesos2=on
resulted in the tests not being picked up by the setup_tests_trilinos_tpetra target.
So is there anything more to do to let the test setup know to pickup that new CMake variable?

@jpthiele jpthiele force-pushed the tpetra-solverdirect branch 2 times, most recently from b55a6fc to 3892b08 Compare February 13, 2024 17:57
@bangerth
Copy link
Member

/rebuild

@jpthiele
Copy link
Contributor Author

Okay figures out how to ensure amesos2 is set up.
The test filename needed an additional 'with', i.e. with_trilinos_with_amesos2=true.

Copy link
Member

@bangerth bangerth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few small issues.

Comment on lines +203 to +218
template <typename Number, typename MemorySpace = dealii::MemorySpace::Host>
class SolverDirect : public SolverDirectBase<Number, MemorySpace>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each of the main classes in this file needs a brief documentation describing what it does.

Comment on lines +99 to +107
// First set whether we want to print the solver information to screen
// or not.
ConditionalOStream verbose_cout(std::cout, output_solver_details);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here and elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this relates to the three lines rule or if you meant anything else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This related to a comment that must have gone lost. I don't think the verbose_cout thing is very useful. Let's use the opportunity to get rid of it here and in all of the other places where we use it in these direct solvers, along with the flag that controls whether to output.

Comment on lines 166 to 182
{}

template <typename Number, typename MemorySpace>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our usual convention is 3 empty lines between functions. This whole file doesn't satisfy this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 391 to 408
{
deallog.push("DirectMEASLES");
LinearAlgebra::TpetraWrappers::SolverDirect<double>::AdditionalData data(
"MEASLES", true);
try
{
LinearAlgebra::TpetraWrappers::SolverDirect<double> direct_solver(
solver_control, data);
}
catch (dealii::ExceptionBase &exc)
{
deallog << "Error: " << std::endl;
exc.print_info(deallog.get_file_stream());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is purposefully a non-existent solver, right? Perhaps add a comment in front of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jpthiele
Copy link
Contributor Author

If have added the missing documentation for the classes and structs.
If any formulation is difficult to understand or could be improved I'm happy to fix it.

Copy link
Member

@bangerth bangerth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good with the exception of the output thing. Let's merge since it is ready; if you feel like addressing the output thing in a separate PR, go ahead -- or we can leave that as a follow-up and I can just open a github issue.

Comment on lines +99 to +107
// First set whether we want to print the solver information to screen
// or not.
ConditionalOStream verbose_cout(std::cout, output_solver_details);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This related to a comment that must have gone lost. I don't think the verbose_cout thing is very useful. Let's use the opportunity to get rid of it here and in all of the other places where we use it in these direct solvers, along with the flag that controls whether to output.

@bangerth bangerth merged commit c54c999 into dealii:master Feb 17, 2024
16 checks passed
@jpthiele jpthiele deleted the tpetra-solverdirect branch February 17, 2024 16:01
@jpthiele
Copy link
Contributor Author

Ahh yes that must have gone missing.
I've removed it in a new branch and when it is done compiling and testing I will open a PR.

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

4 participants