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 2 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
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ option(POLYSOLVE_WITH_PARDISO "Enable Pardiso library"
option(POLYSOLVE_WITH_HYPRE "Enable hypre" 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,13 @@ 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
target_link_libraries(polysolve_linear PUBLIC Trilinos::Trilinos)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_TRILINOS)
endif()

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

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

find_package(Trilinos COMPONENTS ML Epetra)

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

find_package(MPI)

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

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()
14 changes: 13 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,16 @@
],
"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": [
"solver",
"precond"
],
"doc": "Settings for the Trilinos solver."
},
{
"pointer": "/Eigen::LeastSquaresConjugateGradient/max_iter",
"default": 1000,
Expand Down
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
39 changes: 39 additions & 0 deletions src/polysolve/linear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,42 @@
#ifdef POLYSOLVE_WITH_AMGCL
#include "AMGCL.hpp"
#endif
#ifdef POLYSOLVE_WITH_TRILINOS
#include "TrilinosSolver.hpp"
#endif
#ifdef POLYSOLVE_WITH_CUSOLVER
#include "CuSolverDN.cuh"
#endif
#include <unsupported/Eigen/IterativeSolvers>

////////////////////////////////////////////////////////////////////////////////
Eigen::MatrixXd test_vertices;
Eigen::MatrixXd init_vertices;
std::vector<int> test_boundary_nodes;
Eigen::MatrixXd remove_boundary_vertices(const Eigen::MatrixXd &vertices, const std::vector<int> &boundary_nodes)
Copy link
Member

Choose a reason for hiding this comment

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

what is 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.

Removed

{
// Remove boundary vertices
if (boundary_nodes.empty())
{
return vertices;
}
else
{
std::vector<int> order_nodes = boundary_nodes;
std::sort(order_nodes.begin(), order_nodes.end());
Eigen::MatrixXd out_vertices;
std::vector<int> keep;
for (int i = 0; i < vertices.rows(); i++)
{
if (!std::binary_search(order_nodes.begin(), order_nodes.end(),i))
{
keep.push_back(i);
}
}
out_vertices = vertices(keep, Eigen::all);
return out_vertices;
}
}

namespace polysolve::linear
{
Expand Down Expand Up @@ -377,6 +407,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 +535,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
14 changes: 14 additions & 0 deletions src/polysolve/linear/Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

#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; \
Base(const Base &) = delete; \
Base &operator=(const Base &) = delete;

extern Eigen::MatrixXd init_vertices;
extern Eigen::MatrixXd test_vertices;
extern std::vector<int> test_boundary_nodes;
Eigen::MatrixXd remove_boundary_vertices(const Eigen::MatrixXd &vertices, const std::vector<int> &boundary_nodes);
Copy link
Member

Choose a reason for hiding this comment

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

this should be inside trilinos, not here

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


////////////////////////////////////////////////////////////////////////////////
// TODO:
// - [ ] Support both RowMajor + ColumnMajor sparse matrices
Expand All @@ -25,6 +34,11 @@ namespace spdlog

namespace polysolve::linear
{
#ifdef POLYSOLVE_LARGE_INDEX
Copy link
Member

Choose a reason for hiding this comment

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

why these changes?

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.

typedef Eigen::SparseMatrix<double, Eigen::ColMajor, std::ptrdiff_t> StiffnessMatrix;
#else
typedef Eigen::SparseMatrix<double, Eigen::ColMajor> StiffnessMatrix;
#endif
/**
* @brief Base class for linear solver.
*/
Expand Down
Loading
Loading