You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #13984 from KratosMultiphysics/trilinos/more-consistent-direct-solver-handling
[TrilinosApplication] Better documentation for `FastestDirectSolverList` in `TrilinosSpace` and avoid duplication in `CreateFastestAvailableDirectLinearSolver`
This module provides functionality for creating a linear solver for use with the Trilinos application.
9
-
It includes checking and converting deprecated solver types, checking if the desired solver is compiled, and creating the fastest available direct linear solver.
10
-
11
-
Importing necessary Kratos modules:
12
-
- `KratosMultiphysics` as `KM`
13
-
- `KratosMultiphysics.TrilinosApplication` as `KratosTrilinos`
14
-
15
-
Functions:
16
-
- `_CheckIfTypeIsDeprecated(config)`: Checks and translates deprecated solver names to new names for backward compatibility.
17
-
- `_CheckIfSolverIsCompiled(solver_type)`: Checks if the desired solver is compiled.
18
-
- `ConstructSolver(configuration)`: Constructs the solver based on the given configuration.
19
-
- `CreateFastestAvailableDirectLinearSolver()`: Creates the fastest available direct linear solver.
20
-
21
-
Example:
22
-
config = KM.Parameters({
23
-
"solver_type": "CGSolver"
24
-
})
25
-
solver = ConstructSolver(config)
8
+
@package trilinos_solver_factory
9
+
10
+
@brief Module for creating Trilinos-based linear solvers in Kratos.
11
+
12
+
This module provides essential functionality for configuring and instantiating
13
+
linear solvers specifically designed for the Kratos Trilinos application.
14
+
It ensures robustness and compatibility by:
15
+
* Checking and automatically updating deprecated solver types.
16
+
* Verifying the availability of desired solvers based on the Kratos compilation.
17
+
* Providing a utility to automatically select the most efficient direct solver.
18
+
19
+
@section Module_Functions Public and Internal Functions
20
+
* @c _CheckIfTypeIsDeprecated(config): Internal function to check and translate deprecated solver names.
21
+
* @c _CheckIfSolverIsCompiled(solver_type): Internal function to verify if the solver is available in the compilation.
22
+
* @c ConstructSolver(configuration): Primary function to construct a solver based on user configuration.
23
+
* @c CreateFastestAvailableDirectLinearSolver(): Convenience function to get the best available direct solver.
24
+
25
+
@par Example Usage
26
+
@code
27
+
import KratosMultiphysics as KM
28
+
from . import trilinos_solver_factory # Assuming this module is here
KM.Logger.PrintWarning("Trilinos-Linear-Solver-Factory", "Trying to use Aztec-solver, which was disabled at compile time with TRILINOS_EXCLUDE_AZTEC_SOLVER!")
101
+
returnFalse
102
+
returnTrue
103
+
104
+
# --- 3. Check MultiLevel Solvers ---
105
+
ifsolver_typeinml_solvers:
106
+
ifnothasattr(KratosTrilinos, 'MultiLevelSolver'):
107
+
KM.Logger.PrintWarning("Trilinos-Linear-Solver-Factory", "Trying to use MultiLevelSolver, which was disabled at compile time with TRILINOS_EXCLUDE_ML_SOLVER!")
KM.Logger.PrintWarning("Trilinos-Linear-Solver-Factory", "Trying to use Amesos-solver, which was disabled at compile time with TRILINOS_EXCLUDE_AMESOS_SOLVER!")
125
+
returnFalse
126
+
127
+
# Case B: Only Amesos1 is compiled (Warning for performance)
128
+
ifhas_amesos1andnothas_amesos2:
129
+
KM.Logger.PrintWarning("Trilinos-Linear-Solver-Factory", "Amesos2 not compiled but Amesos is. Recommended to compile Amesos2 for better performance.")
130
+
# 'basker' is strictly an Amesos2 solver, so it fails here
131
+
ifsolver_type=="basker":
132
+
KM.Logger.PrintWarning("Trilinos-Linear-Solver-Factory", "basker is strictly an Amesos2 solver")
133
+
returnFalse
134
+
135
+
# Case C: specific internal solver check
136
+
# Map inputs to (required_factory, internal_trilinos_name)
Creates and returns the fastest available direct linear solver, based on a predefined order and availability.
114
-
115
-
TODO: A proper study of speed must be done, particularly depending of system size would be interesting
116
-
117
-
In Trilinos, the speed of direct solvers like MUMPS, SuperLU_DIST, KLU, and Basker can depend on various factors including the size and sparsity of the matrix, the architecture of the computer system, and the specific characteristics of the problem being solved. Below are some general observations about these solvers:
118
-
119
-
1. MUMPS (MUltifrontal Massively Parallel Sparse Direct Solver):
120
-
- Parallel solver, handles large problems well.
121
-
- Can be used on distributed-memory machines.
122
-
- May have higher memory requirements.
123
-
124
-
2. SuperLU_DIST:
125
-
- Parallel solver, also designed for distributed-memory machines.
126
-
- Often used for large, sparse linear systems.
127
-
- Has good performance on a wide range of problems.
211
+
@brief Creates the fastest available direct linear solver.
128
212
129
-
3. KLU:
130
-
- A serial solver, typically used for smaller problems.
131
-
- Works well for circuit simulation problems and other problems with a similar structure.
132
-
- Generally not suitable for large distributed-memory parallel computations.
213
+
This function attempts to construct and return the most efficient direct linear
214
+
solver available in the current compilation, following a predefined priority
215
+
order (e.g., SuperLU, KLU, etc.) to ensure optimal performance.
133
216
134
-
4. Basker:
135
-
- Also a serial solver, suitable for smaller problems.
136
-
- May not perform as well on larger problems or on distributed-memory systems.
217
+
@return @c ConstructSolver: The fastest direct linear solver instance found.
218
+
The specific type depends on the compilation flags and availability.
137
219
138
-
Here are some considerations for choosing a solver:
220
+
@exception Exception Thrown if, after checking all possibilities, no direct
221
+
linear solver could be successfully constructed due to missing libraries or
222
+
factory failures.
139
223
140
-
- If you are working on a distributed-memory parallel machine and dealing with large problems, you might want to consider MUMPS or SuperLU_DIST.
141
-
- For smaller problems or problems with structure similar to circuit simulation problems, KLU might be a good choice.
142
-
- Basker might be suitable for smaller problems where other solvers are not performing well.
143
-
144
-
Returns:
145
-
ConstructSolver: The fastest available direct linear solver.
146
-
147
-
Raises:
148
-
Exception: If no linear solver could be constructed.
Copy file name to clipboardExpand all lines: applications/TrilinosApplication/trilinos_space.h
+27-1Lines changed: 27 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -873,6 +873,32 @@ class TrilinosSpace
873
873
/**
874
874
* @brief Returns a list of the fastest direct solvers.
875
875
* @details This function returns a vector of strings representing the names of the fastest direct solvers. The order of the solvers in the list may need to be updated and reordered depending on the size of the equation system.
876
+
* In Trilinos, the speed of direct solvers like MUMPS, SuperLU_DIST, KLU, and Basker can depend on various factors including the size and sparsity of the matrix, the architecture of the computer system, and the specific characteristics of the problem being solved. Below are some general observations about these solvers:
877
+
*
878
+
* 1. MUMPS (MUltifrontal Massively Parallel Sparse Direct Solver):
879
+
* - Parallel solver, handles large problems well.
880
+
* - Can be used on distributed-memory machines.
881
+
* - May have higher memory requirements.
882
+
*
883
+
* 2. SuperLU_DIST:
884
+
* - Parallel solver, also designed for distributed-memory machines.
885
+
* - Often used for large, sparse linear systems.
886
+
* - Has good performance on a wide range of problems.
887
+
*
888
+
* 3. KLU:
889
+
* - A serial solver, typically used for smaller problems.
890
+
* - Works well for circuit simulation problems and other problems with a similar structure.
891
+
* - Generally not suitable for large distributed-memory parallel computations.
892
+
* 4. Basker:
893
+
* - Also a serial solver, suitable for smaller problems.
894
+
* - May not perform as well on larger problems or on distributed-memory systems.
895
+
*
896
+
* Here are some considerations for choosing a solver:
897
+
*
898
+
* - If you are working on a distributed-memory parallel machine and dealing with large problems, you might want to consider MUMPS or SuperLU_DIST.
899
+
* - For smaller problems or problems with structure similar to circuit simulation problems, KLU might be a good choice.
900
+
* - Basker might be suitable for smaller problems where other solvers are not performing well.
901
+
* @todo A proper study of speed must be done, particularly depending of system size would be interesting
876
902
* @return A vector of strings containing the names of the fastest direct solvers.
0 commit comments