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 Trilinos for linear solver #69

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ jobs:
- name: Dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt -o Acquire::Retries=3 install \
sudo apt-get update
sudo apt-get -o Acquire::Retries=3 install \
libblas-dev \
libglu1-mesa-dev \
xorg-dev \
mpi \
trilinos-dev \
ccache
echo 'CACHE_PATH=~/.ccache' >> "$GITHUB_ENV"

Expand Down
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ option(POLYSOLVE_WITH_SUPERLU "Enable SuperLU library"
option(POLYSOLVE_WITH_MKL "Enable MKL library" ${POLYSOLVE_NOT_ON_APPLE_SILICON})
option(POLYSOLVE_WITH_CUSOLVER "Enable cuSOLVER library" OFF)
option(POLYSOLVE_WITH_PARDISO "Enable Pardiso library" OFF)
option(POLYSOLVE_WITH_HYPRE "Enable hypre" ON)
option(POLYSOLVE_WITH_HYPRE "Enable hypre" OFF)
Copy link
Member

Choose a reason for hiding this comment

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

on

option(POLYSOLVE_WITH_AMGCL "Use AMGCL" ON)
option(POLYSOLVE_WITH_SPECTRA "Enable Spectra library" ON)
option(POLYSOLVE_WITH_TRILINOS "Enable Trilinos" ON)
option(BUILD_TRILINOS_FROM_SOURCE "Build trilinos from source" OFF)

# Sanitizer options
option(POLYSOLVE_SANITIZE_ADDRESS "Sanitize Address" OFF)
Expand Down Expand Up @@ -217,7 +219,7 @@ include(jse)
target_link_libraries(polysolve_linear PUBLIC jse::jse)

# Hypre (GNU Lesser General Public License)
if(POLYSOLVE_WITH_HYPRE)
if(POLYSOLVE_WITH_HYPRE AND NOT POLYSOLVE_WITH_TRILINOS)
include(hypre)
target_link_libraries(polysolve_linear PUBLIC HYPRE::HYPRE)
target_compile_definitions(polysolve_linear PUBLIC POLYSOLVE_WITH_HYPRE)
Expand Down Expand Up @@ -283,6 +285,17 @@ if(POLYSOLVE_WITH_SPECTRA)
target_compile_definitions(polysolve_linear PUBLIC POLYSOLVE_WITH_SPECTRA)
endif()

# Trilinos
if (POLYSOLVE_WITH_TRILINOS)
include(trilinos)
teseoch marked this conversation as resolved.
Show resolved Hide resolved
if(TARGET Trilinos::Trilinos)
target_link_libraries(polysolve_linear PUBLIC Trilinos::Trilinos)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_TRILINOS)
else()
message(WARNING "Trilinos not found, solver will not be available.")
endif()
endif()

# cuSolver solvers
if(POLYSOLVE_WITH_CUSOLVER)
include(cusolverdn)
Expand Down
43 changes: 43 additions & 0 deletions cmake/recipes/trilinos.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
if(TARGET Trilinos::Trilinos)
return()
endif()

message(STATUS "Third-party: creating target 'Trilinos::Trilinos'")

find_package(Trilinos COMPONENTS ML Epetra)

if(NOT Trilinos_FOUND)
set(POLYSOLVE_WITH_TRILINOS OFF)
message("Trilinos not found.")
endif()

find_package(MPI)

if(NOT MPI_FOUND)
set(POLYSOLVE_WITH_TRILINOS OFF)
message("MPI not found.")
endif()

if(Trilinos_FOUND)
if(MPI_FOUND)
MESSAGE("\nFound Trilinos! Here are the details: ")
MESSAGE(" Trilinos_DIR = ${Trilinos_DIR}")
MESSAGE(" Trilinos_VERSION = ${Trilinos_VERSION}")
MESSAGE(" Trilinos_PACKAGE_LIST = ${Trilinos_PACKAGE_LIST}")
MESSAGE(" Trilinos_LIBRARIES = ${Trilinos_LIBRARIES} ")
MESSAGE(" Trilinos_INCLUDE_DIRS = ${Trilinos_INCLUDE_DIRS} ")
MESSAGE(" Trilinos_TPL_LIST = ${Trilinos_TPL_LIST}")
MESSAGE(" Trilinos_TPL_LIBRARIES = ${Trilinos_TPL_LIBRARIES}")
MESSAGE(" Trilinos_BUILD_SHARED_LIBS = ${Trilinos_BUILD_SHARED_LIBS}")
MESSAGE("End of Trilinos details\n")
# include(trilinos)
if(TARGET Trilinos::Trilinos)
else()
add_library(trilinos INTERFACE)
add_library(Trilinos::Trilinos ALIAS trilinos)
target_include_directories(trilinos INTERFACE ${Trilinos_INCLUDE_DIRS} )
target_link_libraries(trilinos INTERFACE ${Trilinos_LIBRARIES} )
target_link_libraries(trilinos INTERFACE MPI::MPI_C MPI::MPI_CXX )
endif()
endif()
endif()
39 changes: 38 additions & 1 deletion linear-solver-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"Eigen::MINRES",
"Pardiso",
"Hypre",
"AMGCL"
"AMGCL",
"Trilinos"
],
"doc": "Settings for the linear solver."
},
Expand All @@ -42,6 +43,7 @@
"Pardiso",
"Hypre",
"AMGCL",
"Trilinos",
"Eigen::LeastSquaresConjugateGradient",
"Eigen::DGMRES",
"Eigen::ConjugateGradient",
Expand Down Expand Up @@ -153,6 +155,17 @@
],
"doc": "Settings for the AMGCL solver."
},
{
Copy link
Member

Choose a reason for hiding this comment

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

i dont think you need any of these, there are no options for trilinos

Copy link
Member

Choose a reason for hiding this comment

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

you need to add the options from trilinos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

"pointer": "/Trilinos",
"default": null,
"type": "object",
"optional": [
"max_iter",
"tolerance",
"block_size"
],
"doc": "Settings for the Trilinos solver."
},
{
"pointer": "/Eigen::LeastSquaresConjugateGradient/max_iter",
"default": 1000,
Expand Down Expand Up @@ -421,5 +434,29 @@
"default": 0,
"type": "float",
"doc": "Aggregation epsilon strong."
},
{
"pointer": "/Trilinos/max_iter",
"default": 1000,
"type": "int",
"doc": "Maximum number of iterations."
},
{
"pointer": "/Trilinos/block_size",
"default": 3,
"type": "int",
"doc": "Aggregation epsilon strong."
},
{
"pointer": "/Trilinos/tolerance",
"default": 1e-8,
"type": "float",
"doc": "Convergence tolerance."
},
{
"pointer": "/Trilinos/is_nullspace",
"default": false,
"type": "bool",
"doc": "Is nullspace or not."
}
]
2 changes: 2 additions & 0 deletions src/polysolve/linear/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set(SOURCES
Pardiso.hpp
SaddlePointSolver.cpp
SaddlePointSolver.hpp
TrilinosSolver.cpp
TrilinosSolver.hpp
)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})
Expand Down
12 changes: 12 additions & 0 deletions src/polysolve/linear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#ifdef POLYSOLVE_WITH_AMGCL
#include "AMGCL.hpp"
#endif
#ifdef POLYSOLVE_WITH_TRILINOS
#include "TrilinosSolver.hpp"
#endif
#ifdef POLYSOLVE_WITH_CUSOLVER
#include "CuSolverDN.cuh"
#endif
Expand Down Expand Up @@ -377,6 +380,12 @@ namespace polysolve::linear
{
return std::make_unique<AMGCL>();
#endif
#ifdef POLYSOLVE_WITH_TRILINOS
}
else if (solver == "Trilinos")
{
return std::make_unique<TrilinosSolver>();
#endif
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
// Available only with Eigen 3.3.0 and newer
#ifndef POLYSOLVE_LARGE_INDEX
Expand Down Expand Up @@ -499,6 +508,9 @@ namespace polysolve::linear
#ifdef POLYSOLVE_WITH_AMGCL
"AMGCL",
#endif
#ifdef POLYSOLVE_WITH_TRILINOS
"Trilinos",
#endif
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
#ifndef POLYSOLVE_LARGE_INDEX
"Eigen::LeastSquaresConjugateGradient",
Expand Down
4 changes: 4 additions & 0 deletions src/polysolve/linear/Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include <memory>

#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <vector>
Copy link
Member

Choose a reason for hiding this comment

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

these are not necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.


#define POLYSOLVE_DELETE_MOVE_COPY(Base) \
Base(Base &&) = delete; \
Base &operator=(Base &&) = delete; \
Expand Down
Loading
Loading