From 20e0b2cb01e0daf6e9b3f0e1c7f0228d19c2fd41 Mon Sep 17 00:00:00 2001 From: Charlie Vanaret Date: Fri, 25 Oct 2024 00:41:48 +0200 Subject: [PATCH] Added HSL to CMakeLists. HSL can be dummy or official; this is tested via a call to LIBHSL_isfunctional() --- CMakeLists.txt | 21 +++++++++++++----- uno/solvers/MA57/MA57Solver.cpp | 1 - ...SymmetricIndefiniteLinearSolverFactory.hpp | 22 ++++++++++++++++--- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65f757d9..1461cef9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,19 +86,28 @@ function(link_to_uno library_name library_path) message(STATUS "Library ${library_name} was found.") endfunction() -# detect optional libraries: ma57 metis bqpd -find_library(MA57 ma57 NAMES ma57 hsl) -if(NOT MA57) - message(WARNING "Optional library MA57 was not found.") +# HSL or MA57 +find_library(HSL hsl) +if(HSL) + link_to_uno(hsl ${HSL}) else() + message(WARNING "Optional library HSL was not found.") + find_library(MA57 ma57) + if(MA57) + link_to_uno(ma57 ${MA57}) + else() + message(WARNING "Optional library MA57 was not found.") + endif() +endif() +if(HSL OR MA57) list(APPEND UNO_SOURCE_FILES uno/solvers/MA57/MA57Solver.cpp) list(APPEND TESTS_UNO_SOURCE_FILES unotest/MA57SolverTests.cpp) - link_to_uno(ma57 ${MA57}) find_package(BLAS REQUIRED) list(APPEND LIBRARIES ${BLAS_LIBRARIES}) endif() +# METIS find_library(METIS metis) if(NOT METIS) message(WARNING "Optional library METIS was not found.") @@ -106,6 +115,7 @@ else() link_to_uno(metis ${METIS}) endif() +# BQPD find_library(BQPD bqpd) if(NOT BQPD) message(WARNING "Optional library BQPD was not found.") @@ -114,6 +124,7 @@ else() link_to_uno(bqpd ${BQPD}) endif() +# MUMPS find_package(MUMPS) if(NOT MUMPS_LIBRARY) message(WARNING "Optional library MUMPS was not found.") diff --git a/uno/solvers/MA57/MA57Solver.cpp b/uno/solvers/MA57/MA57Solver.cpp index 0e4eaf39..5f5b0d53 100644 --- a/uno/solvers/MA57/MA57Solver.cpp +++ b/uno/solvers/MA57/MA57Solver.cpp @@ -1,7 +1,6 @@ // Copyright (c) 2018-2024 Charlie Vanaret // Licensed under the MIT license. See LICENSE file in the project directory for details. -#include #include #include "MA57Solver.hpp" #include "linear_algebra/SymmetricMatrix.hpp" diff --git a/uno/solvers/SymmetricIndefiniteLinearSolverFactory.hpp b/uno/solvers/SymmetricIndefiniteLinearSolverFactory.hpp index 58f5cc8c..0b285ed1 100644 --- a/uno/solvers/SymmetricIndefiniteLinearSolverFactory.hpp +++ b/uno/solvers/SymmetricIndefiniteLinearSolverFactory.hpp @@ -12,10 +12,18 @@ #include "options/Options.hpp" #include "tools/Logger.hpp" -#ifdef HAS_MA57 +#if defined(HAS_MA57) || defined(HAS_HSL) #include "solvers/MA57/MA57Solver.hpp" #endif +#ifdef HAS_HSL +namespace uno { + extern "C" { + bool LIBHSL_isfunctional(); + } +} +#endif + #ifdef HAS_MUMPS #include "solvers/MUMPS/MUMPSSolver.hpp" #endif @@ -27,7 +35,11 @@ namespace uno { [[maybe_unused]] size_t number_nonzeros, const Options& options) { try { [[maybe_unused]] const std::string& linear_solver_name = options.get_string("linear_solver"); -#ifdef HAS_MA57 +#if defined(HAS_HSL) + if (linear_solver_name == "MA57" && LIBHSL_isfunctional()) { + return std::make_unique(dimension, number_nonzeros); + } +#elif defined(HAS_MA57) if (linear_solver_name == "MA57") { return std::make_unique(dimension, number_nonzeros); } @@ -53,7 +65,11 @@ namespace uno { // return the list of available solvers static std::vector available_solvers() { std::vector solvers{}; -#ifdef HAS_MA57 +#ifdef HAS_HSL + if (LIBHSL_isfunctional()) { + solvers.emplace_back("MA57"); + } +#elif defined(HAS_MA57) solvers.emplace_back("MA57"); #endif #ifdef HAS_MUMPS