Skip to content

Commit 27bda0f

Browse files
authored
Trilinos refactoring and updating (SimVascular#424)
* Trilinos updated: * main packages updates: Epetra->Tpetra; AztecOO->Belos; Ifpack->Ifpack2; ML->MueLu * refactor linear algebra backend to use Teuchos and Kokkos: - wrap Tpetra vectors and matrices with Teuchos::RCP for safer memory management and automatic reference counting. - use Kokkos (via Tpetra::Node/KokkosDeviceWrapperNode) to abstract parallel execution (same code to run efficiently on CPU and GPU theoretically) * removed all static objects * change of IC/ICT preconditioners in favor of RILUK(0)/RILUK(1) * Updating dockerfiles: * removed ubuntu20 and ubuntu22 folders. Created ubunut/ folder that contains dockerfile based on ubuntu-latest * modified the solver/dockerfile to use the ubuntu-latest docker container as a base * Updated dockerfiles and workflow file to use the latest docker container: * simvascular/libraries:latest is the image containing the latest trilinos built * Update the input files of trilinos related test cases for fluid and fsi * increased the maximum iteration number for linear solver * add the fluid case iliac artery with ml preconditioner * Modifications and improvements: * kokkos::finalize has been moved inside the TrilinosImpl class, fixing the compilation errors whenever trilinos is not used * trilinos linear solver residual test has been properly set, fixing first non-linear iteration problem of maxing out the linear iterations reducing excessively and unnecessarily the residual * Updating Trilinos packages list in README.md * Final update on dockerfile * Fix buffer overflow in genBC_Integ_X (set_bc.cpp): * string length was computed incorrectly, leading to silent buffer overflow. * this only surfaced as a critical memory crash when linking with the latest Trilinos libraries. * Changes to CMake to fix coverage and unit test mismatch * Modifying cmake file t ofix the coverage error * Fix coverage target for GCC (lcov/geninfo): - Added --ignore-errors mismatch to avoid geninfo line mismatch errors - Added --rc geninfo_unexecuted_blocks=1 to silence GCC warnings * fix coverage: correct path expansion in 'lcov --remove ' command * Removing the unit tests from coverage * Refactor CMake: unify solver build, exclude unit tests from coverage * Built solver sources into a shared object library (solver_objs) so they can be reused by both the main executable and unit tests. This avoids recompiling solver sources twice when ENABLE_UNIT_TEST is enabled. * Excluded unit tests from code coverage by removing coverage flags from the run_all_unit_tests target (-fno-profile-arcs, -fno-test-coverage). This prevents .gcda files from being generated for test code, ensuring coverage only reflects solver sources. * Removing the unit tests folder '*/CMakeFiles/run_all_unit_tests.dir/*' from the coverage. * Remove '*/CMakeFiles/run_all_unit_tests.dir/*' from the coverage list * Adding the following flags in the Cmake file under the enable_coverage section: * --ignore-errors mismatch --rc geninfo_unexecuted_blocks=1 * --ignore-errors unused These flags allowed to save a coverage file even in presence of errors of mismatch type. Fix some parametres setting in the Trilinos GMRES solver: krylov space, max iteration and max restarts. * Updates in new trilinos implementation: * add timer for the linear solver in Trilinos * add the possibility to read the MueLu Options for the ML preconditioner from file mueluOptions.xml if file is not present built-in parameters are used * Using fsils for the mesh equation in FSI test cases * Fixed allocation problem in the graph creation: * the localt to global map was created in sorted order, while the graph allocated in unsorted order * the graph is now created using the sorted order like the map
1 parent 44fc5ec commit 27bda0f

File tree

23 files changed

+792
-1278
lines changed

23 files changed

+792
-1278
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
test-ubuntu:
4040
name: Test Ubuntu
4141
runs-on: ubuntu-latest
42-
container: simvascular/libraries:ubuntu22
42+
container: simvascular/libraries:latest
4343
needs: check-for-changes
4444
if: ${{ needs.check-for-changes.outputs.run_full_tests == 'true' }}
4545
steps:

Code/Source/solver/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ if(ENABLE_COVERAGE)
290290
# add coverage target
291291
add_custom_target(coverage
292292
# gather data
293-
COMMAND ${LCOV} --directory . --capture --output-file coverage.info
293+
COMMAND ${LCOV} --directory . --capture --output-file coverage.info --ignore-errors mismatch --rc geninfo_unexecuted_blocks=1
294294
# exclude externals
295-
COMMAND ${LCOV} --remove coverage.info -o coverage.info '/usr/*' '/opt/*' '${PROJECT_SOURCE_DIR}/ThirdParty/*' '/Library/*' 'v1/*'
295+
COMMAND ${LCOV} --remove coverage.info -o coverage.info '/usr/*' '/opt/*' "${PROJECT_SOURCE_DIR}/ThirdParty/*" '/Library/*' 'v1/*' --ignore-errors unused
296296
# generate report
297297
COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info
298298
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
@@ -371,5 +371,4 @@ if(ENABLE_UNIT_TEST)
371371
# gtest_discover_tests(runUnitTest)
372372
add_test(NAME all_unit_tests COMMAND run_all_unit_tests)
373373

374-
endif()
375-
374+
endif()

Code/Source/solver/FsilsLinearAlgebra.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ void FsilsLinearAlgebra::initialize(ComMod& com_mod, eqType& lEq)
7979
// Nothing is needed to initialize FSILS.
8080
}
8181

82+
/// @brief Finalize framework.
83+
void FsilsLinearAlgebra::finalize()
84+
{
85+
// Nothing is needed to finalize FSILS.
86+
}
87+
8288
/// @brief Set the linear algebra package for assmbly.
8389
void FsilsLinearAlgebra::set_assembly(consts::LinearAlgebraType atype)
8490
{

Code/Source/solver/FsilsLinearAlgebra.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class FsilsLinearAlgebra : public virtual LinearAlgebra {
2323
virtual void solve(ComMod& com_mod, eqType& lEq, const Vector<int>& incL, const Vector<double>& res);
2424
virtual void set_assembly(consts::LinearAlgebraType atype);
2525
virtual void set_preconditioner(consts::PreconditionerType prec_type);
26+
virtual void finalize();
2627

2728
private:
2829
/// @brief A list of linear algebra interfaces that can be used for assembly.

Code/Source/solver/LinearAlgebra.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class LinearAlgebra {
2727
virtual void set_assembly(consts::LinearAlgebraType assembly_type) = 0;
2828
virtual void set_preconditioner(consts::PreconditionerType prec_type) = 0;
2929
virtual void solve(ComMod& com_mod, eqType& lEq, const Vector<int>& incL, const Vector<double>& res) = 0;
30-
30+
virtual void finalize() = 0;
31+
3132
virtual consts::LinearAlgebraType get_interface_type() { return interface_type; }
3233

3334
consts::LinearAlgebraType interface_type = consts::LinearAlgebraType::none;

Code/Source/solver/PetscLinearAlgebra.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ void PetscLinearAlgebra::initialize(ComMod& com_mod, eqType& lEq)
9090
impl->initialize(com_mod, lEq);
9191
}
9292

93+
void PetscLinearAlgebra::finalize()
94+
{
95+
// No need to finalize PETSc.
96+
}
97+
9398
/// @brief Initialize an FsilsLinearAlgebra object used for assembly.
9499
void PetscLinearAlgebra::initialize_fsils(ComMod& com_mod, eqType& lEq)
95100
{

Code/Source/solver/PetscLinearAlgebra.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class PetscLinearAlgebra : public virtual LinearAlgebra {
2222
virtual void solve(ComMod& com_mod, eqType& lEq, const Vector<int>& incL, const Vector<double>& res);
2323
virtual void set_assembly(consts::LinearAlgebraType assembly_type);
2424
virtual void set_preconditioner(consts::PreconditionerType prec_type);
25+
virtual void finalize();
2526

2627
private:
2728
static std::set<consts::LinearAlgebraType> valid_assemblers;

Code/Source/solver/TrilinosLinearAlgebra.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class TrilinosLinearAlgebra::TrilinosImpl {
2222
void set_preconditioner(consts::PreconditionerType prec_type) {};
2323
void solve(ComMod& com_mod, eqType& lEq, const Vector<int>& incL, const Vector<double>& res) {};
2424
void solve_assembled(ComMod& com_mod, eqType& lEq, const Vector<int>& incL, const Vector<double>& res) {};
25+
void finalize(){};
2526
};
2627
#endif
2728

@@ -113,6 +114,12 @@ void TrilinosLinearAlgebra::initialize(ComMod& com_mod, eqType& lEq)
113114
impl->initialize(com_mod);
114115
}
115116

117+
/// @brief Finalize Trilinos.
118+
void TrilinosLinearAlgebra::finalize()
119+
{
120+
impl->finalize();
121+
}
122+
116123
/// @brief Create an fsils linear algebra interface for assembly.
117124
void TrilinosLinearAlgebra::initialize_fsils(ComMod& com_mod, eqType& lEq)
118125
{

Code/Source/solver/TrilinosLinearAlgebra.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TrilinosLinearAlgebra : public virtual LinearAlgebra {
2323
virtual void set_assembly(consts::LinearAlgebraType atype);
2424
virtual void set_preconditioner(consts::PreconditionerType prec_type);
2525
virtual void solve(ComMod& com_mod, eqType& lEq, const Vector<int>& incL, const Vector<double>& res);
26+
virtual void finalize();
2627

2728
private:
2829
static std::set<consts::LinearAlgebraType> valid_assemblers;

Code/Source/solver/consts.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ const std::set<PreconditionerType> trilinos_preconditioners = {
255255
PreconditionerType::PREC_TRILINOS_BLOCK_JACOBI,
256256
PreconditionerType::PREC_TRILINOS_ILU,
257257
PreconditionerType::PREC_TRILINOS_ILUT,
258-
PreconditionerType::PREC_TRILINOS_IC,
259-
PreconditionerType::PREC_TRILINOS_ICT,
258+
PreconditionerType::PREC_TRILINOS_RILUK0,
259+
PreconditionerType::PREC_TRILINOS_RILUK1,
260260
PreconditionerType::PREC_TRILINOS_ML
261261
};
262262

@@ -286,8 +286,8 @@ const std::map<std::string,PreconditionerType> preconditioner_name_to_type =
286286
{"trilinos-blockjacobi", PreconditionerType::PREC_TRILINOS_BLOCK_JACOBI},
287287
{"trilinos-ilu", PreconditionerType::PREC_TRILINOS_ILU},
288288
{"trilinos-ilut", PreconditionerType::PREC_TRILINOS_ILUT},
289-
{"trilinos-ic", PreconditionerType::PREC_TRILINOS_IC},
290-
{"trilinos-ict", PreconditionerType::PREC_TRILINOS_ICT},
289+
{"trilinos-riluk0", PreconditionerType::PREC_TRILINOS_RILUK0},
290+
{"trilinos-riluk1", PreconditionerType::PREC_TRILINOS_RILUK1},
291291
{"trilinos-ml", PreconditionerType::PREC_TRILINOS_ML},
292292

293293
{"petsc-jacobi", PreconditionerType::PREC_PETSC_JACOBI},
@@ -304,8 +304,8 @@ const std::map<PreconditionerType, std::string> preconditioner_type_to_name {
304304
{PreconditionerType::PREC_TRILINOS_BLOCK_JACOBI, "trilinos-blockjacobi"},
305305
{PreconditionerType::PREC_TRILINOS_ILU, "trilinos-ilu"},
306306
{PreconditionerType::PREC_TRILINOS_ILUT, "trilinos-ilut"},
307-
{PreconditionerType::PREC_TRILINOS_IC, "trilinos-ic"},
308-
{PreconditionerType::PREC_TRILINOS_IC, "trilinos-ict"},
307+
{PreconditionerType::PREC_TRILINOS_RILUK0, "trilinos-riluk0"},
308+
{PreconditionerType::PREC_TRILINOS_RILUK1, "trilinos-riluk1"},
309309
{PreconditionerType::PREC_TRILINOS_ML, "trilinos-ml"},
310310
{PreconditionerType::PREC_PETSC_JACOBI, "petsc-jacobi"},
311311
{PreconditionerType::PREC_PETSC_RCS, "petsc-rcs"}

0 commit comments

Comments
 (0)