Skip to content

Commit

Permalink
Merge pull request #12350 from KratosMultiphysics/core/define-list-fa…
Browse files Browse the repository at this point in the history
…stest-direct-linear-solvers

[Core][TrilinosApplication] Defning list of fastest direct linear solvers.
  • Loading branch information
loumalouomega authored May 7, 2024
2 parents 3d8201e + cecfd56 commit e85a583
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ void AddBasicOperations(pybind11::module& m)
.def("SetValue", SetValue)
//.def("GetValue", GetValue) //deliberately commented out. Only works for local Ids
.def("GatherValues", GatherValues)
.def_static("IsDistributed", &TrilinosSparseSpaceType::IsDistributed)
.def_static("FastestDirectSolverList", &TrilinosSparseSpaceType::FastestDirectSolverList)
;

m.def("CreateCommunicator", CreateCommunicator);
Expand Down
22 changes: 22 additions & 0 deletions applications/TrilinosApplication/trilinos_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,28 @@ class TrilinosSpace
return true;
}

/**
* @brief Returns a list of the fastest direct solvers.
* @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.
* @return A vector of strings containing the names of the fastest direct solvers.
*/
inline static std::vector<std::string> FastestDirectSolverList()
{
// May need to be updated and reordered. In fact I think it depends of the size of the equation system
std::vector<std::string> faster_direct_solvers({
"mumps2", // Amesos2 (if compiled with MUMPS-support)
"mumps", // Amesos (if compiled with MUMPS-support)
"super_lu_dist2", // Amesos2 SuperLUDist (if compiled with MPI-support)
"super_lu_dist", // Amesos SuperLUDist (if compiled with MPI-support)
"amesos2", // Amesos2
"amesos", // Amesos
"klu2", // Amesos2 KLU
"klu", // Amesos KLU
"basker" // Amesos2 Basker
});
return faster_direct_solvers;
}

/**
* @brief This function returns a value from a given vector according to a given index
* @param rX The vector from which values are to be gathered
Expand Down
1 change: 0 additions & 1 deletion kratos/python/add_sparse_matrices_to_python.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
Expand Down
9 changes: 8 additions & 1 deletion kratos/python/add_strategies_to_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,16 @@ namespace Kratos:: Python

auto sparse_space_binder = CreateSpaceInterface< SparseSpaceType >(m,"UblasSparseSpace");
sparse_space_binder.def("TwoNorm", TwoNorm);
//the dot product of two vectors
// The dot product of two vectors
sparse_space_binder.def("Dot", Dot);
sparse_space_binder.def("TransposeMult", TransposeMult);
// Size functions
sparse_space_binder.def("Size", &SparseSpaceType::Size);
sparse_space_binder.def("Size1", &SparseSpaceType::Size1);
sparse_space_binder.def("Size2", &SparseSpaceType::Size2);
// Information functions
sparse_space_binder.def("IsDistributed", &SparseSpaceType::IsDistributed);
sparse_space_binder.def("FastestDirectSolverList", &SparseSpaceType::FastestDirectSolverList);

auto cplx_sparse_space_binder = CreateSpaceInterface< ComplexSparseSpaceType >(m,"UblasComplexSparseSpace");

Expand Down
11 changes: 2 additions & 9 deletions kratos/python_scripts/python_linear_solver_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from KratosMultiphysics import kratos_utilities as kratos_utils
from importlib import import_module


def ConstructSolver(configuration):
if(type(configuration) != KM.Parameters):
raise Exception("input is expected to be provided as a Kratos Parameters object")
Expand All @@ -26,11 +25,7 @@ def CreateFastestAvailableDirectLinearSolver():
if kratos_utils.CheckIfApplicationsAvailable("LinearSolversApplication"):
from KratosMultiphysics import LinearSolversApplication

linear_solvers_by_speed = [
"pardiso_lu", # LinearSolversApplication (if compiled with Intel-support)
"sparse_lu", # LinearSolversApplication
"skyline_lu_factorization" # in Core, always available, but slow
]
linear_solvers_by_speed = KM.UblasSparseSpace.FastestDirectSolverList()

for solver_name in linear_solvers_by_speed:
if KM.LinearSolverFactory().Has(solver_name):
Expand All @@ -41,7 +36,6 @@ def CreateFastestAvailableDirectLinearSolver():

raise Exception("Linear-Solver could not be constructed!")


def __GetSolverTypeAndImportApplication(solver_type):
# remove unused "KratosMultiphysics.
if solver_type.startswith("KratosMultiphysics."):
Expand All @@ -57,5 +51,4 @@ def __GetSolverTypeAndImportApplication(solver_type):
solver_type = splitted_name[1]
import_module("KratosMultiphysics." + app_name)

return solver_type

return solver_type
16 changes: 16 additions & 0 deletions kratos/spaces/ublas_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,22 @@ class UblasSpace
return false;
}

/**
* @brief Returns a list of the fastest direct solvers.
* @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.
* @return A vector of strings containing the names of the fastest direct solvers.
*/
inline static std::vector<std::string> FastestDirectSolverList()
{
std::vector<std::string> faster_direct_solvers({
"pardiso_lu", // LinearSolversApplication (if compiled with Intel-support)
"pardiso_ldlt", // LinearSolversApplication (if compiled with Intel-support)
"sparse_lu", // LinearSolversApplication
"skyline_lu_factorization" // In Core, always available, but slow
});
return faster_direct_solvers;
}

//***********************************************************************

inline static TDataType GetValue(const VectorType& x, std::size_t I)
Expand Down

0 comments on commit e85a583

Please sign in to comment.