From ebfe528b40ff22e670cc06bce8f80b3f085f366b Mon Sep 17 00:00:00 2001 From: pelesh Date: Mon, 20 Jan 2025 19:41:13 -0500 Subject: [PATCH 01/13] Add parameter settings for direct solvers. --- resolve/LinSolver.hpp | 35 ++--------- resolve/LinSolverDirectCpuILU0.cpp | 63 +++++++++++++++++++ resolve/LinSolverDirectCpuILU0.hpp | 7 +++ resolve/LinSolverDirectCuSolverGLU.cpp | 62 +++++++++++++++++++ resolve/LinSolverDirectCuSolverGLU.hpp | 11 +++- resolve/LinSolverDirectCuSolverRf.cpp | 77 +++++++++++++++++++++++- resolve/LinSolverDirectCuSolverRf.hpp | 16 ++++- resolve/LinSolverDirectCuSparseILU0.cpp | 63 +++++++++++++++++++ resolve/LinSolverDirectCuSparseILU0.hpp | 6 ++ resolve/LinSolverDirectKLU.cpp | 62 +++++++++++++++++++ resolve/LinSolverDirectKLU.hpp | 7 +++ resolve/LinSolverDirectLUSOL.cpp | 61 +++++++++++++++++++ resolve/LinSolverDirectLUSOL.hpp | 7 +++ resolve/LinSolverDirectRocSolverRf.cpp | 67 +++++++++++++++++++++ resolve/LinSolverDirectRocSolverRf.hpp | 7 +++ resolve/LinSolverDirectRocSparseILU0.cpp | 63 +++++++++++++++++++ resolve/LinSolverDirectRocSparseILU0.hpp | 6 ++ resolve/LinSolverDirectSerialILU0.cpp | 64 ++++++++++++++++++++ resolve/LinSolverDirectSerialILU0.hpp | 12 +++- 19 files changed, 657 insertions(+), 39 deletions(-) diff --git a/resolve/LinSolver.hpp b/resolve/LinSolver.hpp index 3be52cea..f04d8109 100644 --- a/resolve/LinSolver.hpp +++ b/resolve/LinSolver.hpp @@ -48,35 +48,12 @@ namespace ReSolve real_type evaluateResidual(); - virtual int setCliParam(const std::string /* id */, const std::string /* value */) - { - return 1; - } - - virtual std::string getCliParamString(const std::string /* id */) const - { - return ""; - } - - virtual index_type getCliParamInt(const std::string /* id */) const - { - return -1; - } - - virtual real_type getCliParamReal(const std::string /* id */) const - { - return 1.0; - } - - virtual bool getCliParamBool(const std::string /* id */) const - { - return false; - } - - virtual int printCliParam(const std::string /* id */) const - { - return 1; - } + virtual int setCliParam(const std::string /* id */, const std::string /* value */) = 0; + virtual std::string getCliParamString(const std::string /* id */) const = 0; + virtual index_type getCliParamInt(const std::string /* id */) const = 0; + virtual real_type getCliParamReal(const std::string /* id */) const = 0; + virtual bool getCliParamBool(const std::string /* id */) const = 0; + virtual int printCliParam(const std::string /* id */) const = 0; protected: int getParamId(std::string id) const; diff --git a/resolve/LinSolverDirectCpuILU0.cpp b/resolve/LinSolverDirectCpuILU0.cpp index 6de783a1..20f8d906 100644 --- a/resolve/LinSolverDirectCpuILU0.cpp +++ b/resolve/LinSolverDirectCpuILU0.cpp @@ -16,6 +16,8 @@ namespace ReSolve { + using out = io::Logger; + LinSolverDirectCpuILU0::LinSolverDirectCpuILU0(LinAlgWorkspaceCpu* /* workspace */) // : workspace_(workspace) { @@ -345,4 +347,65 @@ namespace ReSolve return 0; } + int LinSolverDirectCpuILU0::setCliParam(const std::string id, const std::string value) + { + switch (getParamId(id)) + { + default: + std::cout << "Setting parameter failed!\n"; + } + return 0; + } + + std::string LinSolverDirectCpuILU0::getCliParamString(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown string parameter " << id << "\n"; + } + return ""; + } + + index_type LinSolverDirectCpuILU0::getCliParamInt(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown integer parameter " << id << "\n"; + } + return -1; + } + + real_type LinSolverDirectCpuILU0::getCliParamReal(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown real parameter " << id << "\n"; + } + return std::numeric_limits::quiet_NaN(); + } + + bool LinSolverDirectCpuILU0::getCliParamBool(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown boolean parameter " << id << "\n"; + } + return false; + } + + int LinSolverDirectCpuILU0::printCliParam(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; + } + return 0; + } + } // namespace resolve diff --git a/resolve/LinSolverDirectCpuILU0.hpp b/resolve/LinSolverDirectCpuILU0.hpp index 8ade9e7a..dbde29e2 100644 --- a/resolve/LinSolverDirectCpuILU0.hpp +++ b/resolve/LinSolverDirectCpuILU0.hpp @@ -67,6 +67,13 @@ namespace ReSolve int setZeroDiagonal(real_type z); + int setCliParam(const std::string id, const std::string value) override; + std::string getCliParamString(const std::string id) const override; + index_type getCliParamInt(const std::string id) const override; + real_type getCliParamReal(const std::string id) const override; + bool getCliParamBool(const std::string id) const override; + int printCliParam(const std::string id) const override; + private: // MemoryHandler mem_; ///< Device memory manager object // LinAlgWorkspaceCpu* workspace_{nullptr}; diff --git a/resolve/LinSolverDirectCuSolverGLU.cpp b/resolve/LinSolverDirectCuSolverGLU.cpp index eb91fc76..0bd5dd28 100644 --- a/resolve/LinSolverDirectCuSolverGLU.cpp +++ b/resolve/LinSolverDirectCuSolverGLU.cpp @@ -199,4 +199,66 @@ namespace ReSolve << "Consider using solve(Vector* rhs, Vector* x) instead.\n"; return 1; } + + int LinSolverDirectCuSolverGLU::setCliParam(const std::string id, const std::string value) + { + switch (getParamId(id)) + { + default: + std::cout << "Setting parameter failed!\n"; + } + return 0; + } + + std::string LinSolverDirectCuSolverGLU::getCliParamString(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown string parameter " << id << "\n"; + } + return ""; + } + + index_type LinSolverDirectCuSolverGLU::getCliParamInt(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown integer parameter " << id << "\n"; + } + return -1; + } + + real_type LinSolverDirectCuSolverGLU::getCliParamReal(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown real parameter " << id << "\n"; + } + return std::numeric_limits::quiet_NaN(); + } + + bool LinSolverDirectCuSolverGLU::getCliParamBool(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown boolean parameter " << id << "\n"; + } + return false; + } + + int LinSolverDirectCuSolverGLU::printCliParam(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; + } + return 0; + } + } diff --git a/resolve/LinSolverDirectCuSolverGLU.hpp b/resolve/LinSolverDirectCuSolverGLU.hpp index e2af4874..a4c11823 100644 --- a/resolve/LinSolverDirectCuSolverGLU.hpp +++ b/resolve/LinSolverDirectCuSolverGLU.hpp @@ -42,6 +42,13 @@ namespace ReSolve index_type* Q, vector_type* rhs = nullptr) override; + int setCliParam(const std::string id, const std::string value) override; + std::string getCliParamString(const std::string id) const override; + index_type getCliParamInt(const std::string id) const override; + real_type getCliParamReal(const std::string id) const override; + bool getCliParamBool(const std::string id) const override; + int printCliParam(const std::string id) const override; + private: void addFactors(matrix::Sparse* L, matrix::Sparse* U); ///< creates L+U from sepeate L, U factors matrix::Sparse* M_; ///< the matrix that contains added factors @@ -54,8 +61,8 @@ namespace ReSolve cusparseStatus_t status_cusparse_; csrgluInfo_t info_M_; void* glu_buffer_; - double r_nrminf_; - int ite_refine_succ_; + double r_nrminf_; ///< Error norm of the solution + int ite_refine_succ_; ///< Stores return value of cusolverSpDgluSolve MemoryHandler mem_; ///< Device memory manager object }; diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index 8c2d04a5..70364c21 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -4,6 +4,8 @@ namespace ReSolve { + using out = io::Logger; + LinSolverDirectCuSolverRf::LinSolverDirectCuSolverRf(LinAlgWorkspaceCUDA* /* workspace */) { cusolverRfCreate(&handle_cusolverrf_); @@ -92,7 +94,8 @@ namespace ReSolve return error_sum; } - void LinSolverDirectCuSolverRf::setAlgorithms(cusolverRfFactorization_t fact_alg, cusolverRfTriangularSolve_t solve_alg) + void LinSolverDirectCuSolverRf::setAlgorithms(cusolverRfFactorization_t fact_alg, + cusolverRfTriangularSolve_t solve_alg) { cusolverRfSetAlgs(handle_cusolverrf_, fact_alg, solve_alg); } @@ -146,9 +149,77 @@ namespace ReSolve return status_cusolverrf_; } - int LinSolverDirectCuSolverRf::setNumericalProperties(double nzero, double nboost) + int LinSolverDirectCuSolverRf::setNumericalProperties(real_type nzero, + real_type nboost) { - status_cusolverrf_ = cusolverRfSetNumericProperties(handle_cusolverrf_, nzero, nboost); + // Zero flagging threshold and boost NEED TO BE DOUBLE! + double zero = static_cast(nzero); + double boost = static_cast(nboost); + status_cusolverrf_ = cusolverRfSetNumericProperties(handle_cusolverrf_, + nzero, + nboost); return status_cusolverrf_; } + + int LinSolverDirectCuSolverRf::setCliParam(const std::string id, const std::string value) + { + switch (getParamId(id)) + { + default: + std::cout << "Setting parameter failed!\n"; + } + return 0; + } + + std::string LinSolverDirectCuSolverRf::getCliParamString(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown string parameter " << id << "\n"; + } + return ""; + } + + index_type LinSolverDirectCuSolverRf::getCliParamInt(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown integer parameter " << id << "\n"; + } + return -1; + } + + real_type LinSolverDirectCuSolverRf::getCliParamReal(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown real parameter " << id << "\n"; + } + return std::numeric_limits::quiet_NaN(); + } + + bool LinSolverDirectCuSolverRf::getCliParamBool(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown boolean parameter " << id << "\n"; + } + return false; + } + + int LinSolverDirectCuSolverRf::printCliParam(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; + } + return 0; + } + }// namespace resolve diff --git a/resolve/LinSolverDirectCuSolverRf.hpp b/resolve/LinSolverDirectCuSolverRf.hpp index a0734c2e..4c069f6d 100644 --- a/resolve/LinSolverDirectCuSolverRf.hpp +++ b/resolve/LinSolverDirectCuSolverRf.hpp @@ -42,8 +42,17 @@ namespace ReSolve int solve(vector_type* rhs, vector_type* x) override; int solve(vector_type* rhs) override; // rhs overwritten by solution - void setAlgorithms(cusolverRfFactorization_t fact_alg, cusolverRfTriangularSolve_t solve_alg); - int setNumericalProperties(double nzero, double nboost);//these two NEED TO BE DOUBLE + void setAlgorithms(cusolverRfFactorization_t fact_alg, + cusolverRfTriangularSolve_t solve_alg); + int setNumericalProperties(real_type nzero, real_type nboost); + + int setCliParam(const std::string id, const std::string value) override; + std::string getCliParamString(const std::string id) const override; + index_type getCliParamInt(const std::string id) const override; + real_type getCliParamReal(const std::string id) const override; + bool getCliParamBool(const std::string id) const override; + int printCliParam(const std::string id) const override; + private: cusolverRfHandle_t handle_cusolverrf_; cusolverStatus_t status_cusolverrf_; @@ -52,6 +61,9 @@ namespace ReSolve index_type* d_Q_{nullptr}; real_type* d_T_{nullptr}; bool setup_completed_{false}; + + real_type zero_pivot_{0.0}; ///< The value below which zero pivot is flagged. + real_type pivot_boost_{0.0}; ///< The value which is substituted for zero pivot. MemoryHandler mem_; ///< Device memory manager object }; diff --git a/resolve/LinSolverDirectCuSparseILU0.cpp b/resolve/LinSolverDirectCuSparseILU0.cpp index 0b3b9666..0e38d1dc 100644 --- a/resolve/LinSolverDirectCuSparseILU0.cpp +++ b/resolve/LinSolverDirectCuSparseILU0.cpp @@ -5,6 +5,8 @@ namespace ReSolve { + using out = io::Logger; + LinSolverDirectCuSparseILU0::LinSolverDirectCuSparseILU0(LinAlgWorkspaceCUDA* workspace) { workspace_ = workspace; @@ -311,4 +313,65 @@ namespace ReSolve return error_sum; } + int LinSolverDirectCuSparseILU0::setCliParam(const std::string id, const std::string value) + { + switch (getParamId(id)) + { + default: + std::cout << "Setting parameter failed!\n"; + } + return 0; + } + + std::string LinSolverDirectCuSparseILU0::getCliParamString(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown string parameter " << id << "\n"; + } + return ""; + } + + index_type LinSolverDirectCuSparseILU0::getCliParamInt(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown integer parameter " << id << "\n"; + } + return -1; + } + + real_type LinSolverDirectCuSparseILU0::getCliParamReal(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown real parameter " << id << "\n"; + } + return std::numeric_limits::quiet_NaN(); + } + + bool LinSolverDirectCuSparseILU0::getCliParamBool(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown boolean parameter " << id << "\n"; + } + return false; + } + + int LinSolverDirectCuSparseILU0::printCliParam(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; + } + return 0; + } + } // namespace resolve diff --git a/resolve/LinSolverDirectCuSparseILU0.hpp b/resolve/LinSolverDirectCuSparseILU0.hpp index 0a99de8f..b5817a10 100644 --- a/resolve/LinSolverDirectCuSparseILU0.hpp +++ b/resolve/LinSolverDirectCuSparseILU0.hpp @@ -42,6 +42,12 @@ namespace ReSolve int solve(vector_type* rhs, vector_type* x) override; int solve(vector_type* rhs) override; + int setCliParam(const std::string id, const std::string value) override; + std::string getCliParamString(const std::string id) const override; + index_type getCliParamInt(const std::string id) const override; + real_type getCliParamReal(const std::string id) const override; + bool getCliParamBool(const std::string id) const override; + int printCliParam(const std::string id) const override; private: cusparseStatus_t status_cusparse_; diff --git a/resolve/LinSolverDirectKLU.cpp b/resolve/LinSolverDirectKLU.cpp index beb49c7f..a45f00eb 100644 --- a/resolve/LinSolverDirectKLU.cpp +++ b/resolve/LinSolverDirectKLU.cpp @@ -286,4 +286,66 @@ namespace ReSolve klu_rcond(Symbolic_, Numeric_, &Common_); return Common_.rcond; } + + int LinSolverDirectKLU::setCliParam(const std::string id, const std::string value) + { + switch (getParamId(id)) + { + default: + std::cout << "Setting parameter failed!\n"; + } + return 0; + } + + std::string LinSolverDirectKLU::getCliParamString(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown string parameter " << id << "\n"; + } + return ""; + } + + index_type LinSolverDirectKLU::getCliParamInt(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown integer parameter " << id << "\n"; + } + return -1; + } + + real_type LinSolverDirectKLU::getCliParamReal(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown real parameter " << id << "\n"; + } + return std::numeric_limits::quiet_NaN(); + } + + bool LinSolverDirectKLU::getCliParamBool(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown boolean parameter " << id << "\n"; + } + return false; + } + + int LinSolverDirectKLU::printCliParam(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; + } + return 0; + } + } // namespace ReSolve diff --git a/resolve/LinSolverDirectKLU.hpp b/resolve/LinSolverDirectKLU.hpp index ecec7a24..8024065b 100644 --- a/resolve/LinSolverDirectKLU.hpp +++ b/resolve/LinSolverDirectKLU.hpp @@ -51,6 +51,13 @@ namespace ReSolve virtual real_type getMatrixConditionNumber() override; + int setCliParam(const std::string id, const std::string value) override; + std::string getCliParamString(const std::string id) const override; + index_type getCliParamInt(const std::string id) const override; + real_type getCliParamReal(const std::string id) const override; + bool getCliParamBool(const std::string id) const override; + int printCliParam(const std::string id) const override; + private: bool factors_extracted_{false}; klu_common Common_; //settings diff --git a/resolve/LinSolverDirectLUSOL.cpp b/resolve/LinSolverDirectLUSOL.cpp index c734cb83..3d31cb35 100644 --- a/resolve/LinSolverDirectLUSOL.cpp +++ b/resolve/LinSolverDirectLUSOL.cpp @@ -473,6 +473,67 @@ namespace ReSolve return 0; } + int LinSolverDirectLUSOL::setCliParam(const std::string id, const std::string value) + { + switch (getParamId(id)) + { + default: + std::cout << "Setting parameter failed!\n"; + } + return 0; + } + + std::string LinSolverDirectLUSOL::getCliParamString(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown string parameter " << id << "\n"; + } + return ""; + } + + index_type LinSolverDirectLUSOL::getCliParamInt(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown integer parameter " << id << "\n"; + } + return -1; + } + + real_type LinSolverDirectLUSOL::getCliParamReal(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown real parameter " << id << "\n"; + } + return std::numeric_limits::quiet_NaN(); + } + + bool LinSolverDirectLUSOL::getCliParamBool(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown boolean parameter " << id << "\n"; + } + return false; + } + + int LinSolverDirectLUSOL::printCliParam(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; + } + return 0; + } + // // Private Methods // diff --git a/resolve/LinSolverDirectLUSOL.hpp b/resolve/LinSolverDirectLUSOL.hpp index 3393f496..df3cf6fd 100644 --- a/resolve/LinSolverDirectLUSOL.hpp +++ b/resolve/LinSolverDirectLUSOL.hpp @@ -64,6 +64,13 @@ namespace ReSolve virtual real_type getMatrixConditionNumber() override; + int setCliParam(const std::string id, const std::string value) override; + std::string getCliParamString(const std::string id) const override; + index_type getCliParamInt(const std::string id) const override; + real_type getCliParamReal(const std::string id) const override; + bool getCliParamBool(const std::string id) const override; + int printCliParam(const std::string id) const override; + private: int allocateSolverData(); int freeSolverData(); diff --git a/resolve/LinSolverDirectRocSolverRf.cpp b/resolve/LinSolverDirectRocSolverRf.cpp index 320b66fc..c32c5f37 100644 --- a/resolve/LinSolverDirectRocSolverRf.cpp +++ b/resolve/LinSolverDirectRocSolverRf.cpp @@ -6,6 +6,8 @@ namespace ReSolve { + using out = io::Logger; + LinSolverDirectRocSolverRf::LinSolverDirectRocSolverRf(LinAlgWorkspaceHIP* workspace) { workspace_ = workspace; @@ -377,6 +379,71 @@ namespace ReSolve return solve_mode_; } + int LinSolverDirectRocSolverRf::setCliParam(const std::string id, const std::string value) + { + switch (getParamId(id)) + { + default: + std::cout << "Setting parameter failed!\n"; + } + return 0; + } + + std::string LinSolverDirectRocSolverRf::getCliParamString(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown string parameter " << id << "\n"; + } + return ""; + } + + index_type LinSolverDirectRocSolverRf::getCliParamInt(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown integer parameter " << id << "\n"; + } + return -1; + } + + real_type LinSolverDirectRocSolverRf::getCliParamReal(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown real parameter " << id << "\n"; + } + return std::numeric_limits::quiet_NaN(); + } + + bool LinSolverDirectRocSolverRf::getCliParamBool(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown boolean parameter " << id << "\n"; + } + return false; + } + + int LinSolverDirectRocSolverRf::printCliParam(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; + } + return 0; + } + + // + // Private methods + // + void LinSolverDirectRocSolverRf::addFactors(matrix::Sparse* L, matrix::Sparse* U) { // L and U need to be in CSC format diff --git a/resolve/LinSolverDirectRocSolverRf.hpp b/resolve/LinSolverDirectRocSolverRf.hpp index 244dbe55..3b09bd2d 100644 --- a/resolve/LinSolverDirectRocSolverRf.hpp +++ b/resolve/LinSolverDirectRocSolverRf.hpp @@ -47,6 +47,13 @@ namespace ReSolve int setSolveMode(int mode); // should probably be enum int getSolveMode(); //should be enum too + int setCliParam(const std::string id, const std::string value) override; + std::string getCliParamString(const std::string id) const override; + index_type getCliParamInt(const std::string id) const override; + real_type getCliParamReal(const std::string id) const override; + bool getCliParamBool(const std::string id) const override; + int printCliParam(const std::string id) const override; + private: rocblas_status status_rocblas_; rocsparse_status status_rocsparse_; diff --git a/resolve/LinSolverDirectRocSparseILU0.cpp b/resolve/LinSolverDirectRocSparseILU0.cpp index b996f47d..669daa63 100644 --- a/resolve/LinSolverDirectRocSparseILU0.cpp +++ b/resolve/LinSolverDirectRocSparseILU0.cpp @@ -6,6 +6,8 @@ namespace ReSolve { + using out = io::Logger; + LinSolverDirectRocSparseILU0::LinSolverDirectRocSparseILU0(LinAlgWorkspaceHIP* workspace) { workspace_ = workspace; @@ -291,4 +293,65 @@ namespace ReSolve return error_sum; } + int LinSolverDirectRocSparseILU0::setCliParam(const std::string id, const std::string value) + { + switch (getParamId(id)) + { + default: + std::cout << "Setting parameter failed!\n"; + } + return 0; + } + + std::string LinSolverDirectRocSparseILU0::getCliParamString(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown string parameter " << id << "\n"; + } + return ""; + } + + index_type LinSolverDirectRocSparseILU0::getCliParamInt(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown integer parameter " << id << "\n"; + } + return -1; + } + + real_type LinSolverDirectRocSparseILU0::getCliParamReal(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown real parameter " << id << "\n"; + } + return std::numeric_limits::quiet_NaN(); + } + + bool LinSolverDirectRocSparseILU0::getCliParamBool(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown boolean parameter " << id << "\n"; + } + return false; + } + + int LinSolverDirectRocSparseILU0::printCliParam(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; + } + return 0; + } + }// namespace resolve diff --git a/resolve/LinSolverDirectRocSparseILU0.hpp b/resolve/LinSolverDirectRocSparseILU0.hpp index 36f31c2b..7b9f9f67 100644 --- a/resolve/LinSolverDirectRocSparseILU0.hpp +++ b/resolve/LinSolverDirectRocSparseILU0.hpp @@ -44,6 +44,12 @@ namespace ReSolve int solve(vector_type* rhs, vector_type* x) override; int solve(vector_type* rhs) override; // the solution is returned IN RHS (rhs is overwritten) + int setCliParam(const std::string id, const std::string value) override; + std::string getCliParamString(const std::string id) const override; + index_type getCliParamInt(const std::string id) const override; + real_type getCliParamReal(const std::string id) const override; + bool getCliParamBool(const std::string id) const override; + int printCliParam(const std::string id) const override; private: rocsparse_status status_rocsparse_; diff --git a/resolve/LinSolverDirectSerialILU0.cpp b/resolve/LinSolverDirectSerialILU0.cpp index 39e6f4ab..2e9bc4cb 100644 --- a/resolve/LinSolverDirectSerialILU0.cpp +++ b/resolve/LinSolverDirectSerialILU0.cpp @@ -7,6 +7,8 @@ namespace ReSolve { + using out = io::Logger; + LinSolverDirectSerialILU0::LinSolverDirectSerialILU0(LinAlgWorkspaceCpu* workspace) { workspace_ = workspace; @@ -236,4 +238,66 @@ namespace ReSolve //for (int ii=0; ii<10; ++ii) printf("(LU)^{-1}y[%d] = %16.16f \n ", ii, x->getData(ReSolve::memory::HOST)[ii]); return error_sum; } + + int LinSolverDirectSerialILU0::setCliParam(const std::string id, const std::string value) + { + switch (getParamId(id)) + { + default: + std::cout << "Setting parameter failed!\n"; + } + return 0; + } + + std::string LinSolverDirectSerialILU0::getCliParamString(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown string parameter " << id << "\n"; + } + return ""; + } + + index_type LinSolverDirectSerialILU0::getCliParamInt(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown integer parameter " << id << "\n"; + } + return -1; + } + + real_type LinSolverDirectSerialILU0::getCliParamReal(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown real parameter " << id << "\n"; + } + return std::numeric_limits::quiet_NaN(); + } + + bool LinSolverDirectSerialILU0::getCliParamBool(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to get unknown boolean parameter " << id << "\n"; + } + return false; + } + + int LinSolverDirectSerialILU0::printCliParam(const std::string id) const + { + switch (getParamId(id)) + { + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; + } + return 0; + } + } // namespace resolve diff --git a/resolve/LinSolverDirectSerialILU0.hpp b/resolve/LinSolverDirectSerialILU0.hpp index 7f667a62..7dc4914a 100644 --- a/resolve/LinSolverDirectSerialILU0.hpp +++ b/resolve/LinSolverDirectSerialILU0.hpp @@ -33,12 +33,18 @@ namespace ReSolve matrix::Sparse* U = nullptr, index_type* P = nullptr, index_type* Q = nullptr, - vector_type* rhs = nullptr); + vector_type* rhs = nullptr) override; int reset(matrix::Sparse* A); - int solve(vector_type* rhs, vector_type* x); - int solve(vector_type* rhs);// the solutuon is returned IN RHS (rhs is overwritten) + int solve(vector_type* rhs, vector_type* x) override; + int solve(vector_type* rhs) override; // the solutuon is returned IN RHS (rhs is overwritten) + int setCliParam(const std::string id, const std::string value) override; + std::string getCliParamString(const std::string id) const override; + index_type getCliParamInt(const std::string id) const override; + real_type getCliParamReal(const std::string id) const override; + bool getCliParamBool(const std::string id) const override; + int printCliParam(const std::string id) const override; private: From 2c91356e8f63e4f4256f1091273aec20110ab598 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Tue, 21 Jan 2025 21:40:51 -0500 Subject: [PATCH 02/13] Parameter seting for rocsolverRf. --- resolve/LinSolverDirectRocSolverRf.cpp | 43 ++++++++++++++++--- resolve/LinSolverDirectRocSolverRf.hpp | 21 +++++---- .../testKLU_RocSolver_FGMRES.cpp | 13 +++--- 3 files changed, 57 insertions(+), 20 deletions(-) diff --git a/resolve/LinSolverDirectRocSolverRf.cpp b/resolve/LinSolverDirectRocSolverRf.cpp index c32c5f37..b63938e1 100644 --- a/resolve/LinSolverDirectRocSolverRf.cpp +++ b/resolve/LinSolverDirectRocSolverRf.cpp @@ -12,7 +12,8 @@ namespace ReSolve { workspace_ = workspace; infoM_ = nullptr; - solve_mode_ = 1; //solve mode - fast mode is default + solve_mode_ = 1; //solve mode - 1: use rocsparse trisolve + initParamList(); } LinSolverDirectRocSolverRf::~LinSolverDirectRocSolverRf() @@ -35,19 +36,24 @@ namespace ReSolve vector_type* rhs) { RESOLVE_RANGE_PUSH(__FUNCTION__); - //remember - P and Q are generally CPU variables + int error_sum = 0; - this->A_ = (matrix::Csr*) A; + + assert(A->getSparseFormat() == matrix::Sparse::COMPRESSED_SPARSE_ROW && + "Matrix has to be in CSR format for rocsolverRf.\n"); + A_ = A; index_type n = A_->getNumRows(); + //set matrix info rocsolver_create_rfinfo(&infoM_, workspace_->getRocblasHandle()); - //create combined factor + // Combine factors L and U into matrix M_ addFactors(L, U); M_->setUpdated(ReSolve::memory::HOST); M_->syncData(ReSolve::memory::DEVICE); + //remember - P and Q are generally CPU variables if (d_P_ == nullptr) { mem_.allocateArrayOnDevice(&d_P_, n); } @@ -374,7 +380,7 @@ namespace ReSolve return 0; } - int LinSolverDirectRocSolverRf::getSolveMode() + int LinSolverDirectRocSolverRf::getSolveMode() const { return solve_mode_; } @@ -383,6 +389,15 @@ namespace ReSolve { switch (getParamId(id)) { + case SOLVE_MODE: + if (value == "rocsparse_trisolve") { + // use rocsparse triangular solver + setSolveMode(1); + } else { + // use default + setSolveMode(0); + } + break; default: std::cout << "Setting parameter failed!\n"; } @@ -391,12 +406,23 @@ namespace ReSolve std::string LinSolverDirectRocSolverRf::getCliParamString(const std::string id) const { + std::string value(""); switch (getParamId(id)) { + case SOLVE_MODE: + switch (getSolveMode()) + { + case 0: + value = "default"; + break; + case 1: + value = "rocsparse_trisolve"; + break; + } default: out::error() << "Trying to get unknown string parameter " << id << "\n"; } - return ""; + return value; } index_type LinSolverDirectRocSolverRf::getCliParamInt(const std::string id) const @@ -503,4 +529,9 @@ namespace ReSolve } } } // LinSolverDirectRocSolverRf::addFactors + + void LinSolverDirectRocSolverRf::initParamList() + { + params_list_["solve_mode"] = SOLVE_MODE; + } } // namespace resolve diff --git a/resolve/LinSolverDirectRocSolverRf.hpp b/resolve/LinSolverDirectRocSolverRf.hpp index 3b09bd2d..49340017 100644 --- a/resolve/LinSolverDirectRocSolverRf.hpp +++ b/resolve/LinSolverDirectRocSolverRf.hpp @@ -38,14 +38,14 @@ namespace ReSolve matrix::Sparse* U, index_type* P, index_type* Q, - vector_type* rhs); + vector_type* rhs) override; - int refactorize(); - int solve(vector_type* rhs, vector_type* x); - int solve(vector_type* rhs);// the solution is returned IN RHS (rhs is overwritten) + int refactorize() override; + int solve(vector_type* rhs, vector_type* x) override; + int solve(vector_type* rhs) override; // the solution overwrites rhs int setSolveMode(int mode); // should probably be enum - int getSolveMode(); //should be enum too + int getSolveMode() const; //should be enum too int setCliParam(const std::string id, const std::string value) override; std::string getCliParamString(const std::string id) const override; @@ -55,6 +55,14 @@ namespace ReSolve int printCliParam(const std::string id) const override; private: + enum ParamaterIDs {SOLVE_MODE=0}; + int solve_mode_{0}; // 0 - default; 1 - use rocparse trisolver + + private: + // to be exported to matrix handler in a later time + void addFactors(matrix::Sparse* L, matrix::Sparse* U); //create L+U from sepeate L, U factors + void initParamList(); + rocblas_status status_rocblas_; rocsparse_status status_rocsparse_; index_type* d_P_{nullptr}; @@ -63,11 +71,8 @@ namespace ReSolve MemoryHandler mem_; ///< Device memory manager object LinAlgWorkspaceHIP* workspace_; - // to be exported to matrix handler in a later time - void addFactors(matrix::Sparse* L, matrix::Sparse* U); //create L+U from sepeate L, U factors rocsolver_rfinfo infoM_; matrix::Sparse* M_{nullptr};//the matrix that contains added factors - int solve_mode_; // 0 is default and 1 is fast // not used by default - for fast solve rocsparse_mat_descr descr_L_{nullptr}; diff --git a/tests/functionality/testKLU_RocSolver_FGMRES.cpp b/tests/functionality/testKLU_RocSolver_FGMRES.cpp index 84573820..fae44851 100644 --- a/tests/functionality/testKLU_RocSolver_FGMRES.cpp +++ b/tests/functionality/testKLU_RocSolver_FGMRES.cpp @@ -168,15 +168,16 @@ int main(int argc, char *argv[]) // Now prepare the Rf solver - ReSolve::matrix::Csc* L = (ReSolve::matrix::Csc*) KLU->getLFactor(); - ReSolve::matrix::Csc* U = (ReSolve::matrix::Csc*) KLU->getUFactor(); + ReSolve::matrix::Csc* L = static_cast(KLU->getLFactor()); + ReSolve::matrix::Csc* U = static_cast(KLU->getUFactor()); if (L == nullptr) { printf("ERROR"); } index_type* P = KLU->getPOrdering(); index_type* Q = KLU->getQOrdering(); - Rf->setSolveMode(1); + Rf->setCliParam("solve_mode", "rocsparse_trisolve"); + // Rf->setCliParam("solve_mode", "default"); vec_rhs->copyDataFrom(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE); error_sum += Rf->setup(A, L, U, P, Q, vec_rhs); FGMRES->setMaxit(200); @@ -261,14 +262,14 @@ int main(int argc, char *argv[]) error_sum++; } // TODO: 1e-9 is too lose acuracy! - if ((normRmatrix1/normB1 > 1e-12 ) || (normRmatrix2/normB2 > 1e-9)) { + if ((normRmatrix1/normB1 > 1e-12 ) || (normRmatrix2/normB2 > 1e-12)) { std::cout << "Result inaccurate!\n"; error_sum++; } if (error_sum == 0) { - std::cout << "Test KLU with cuSolverGLU refactorization " << GREEN << "PASSED" << CLEAR << std::endl; + std::cout << "Test KLU with Rf refactorization and IR " << GREEN << "PASSED" << CLEAR << std::endl; } else { - std::cout << "Test KLU with cuSolverGLU refactorization " << RED << "FAILED" << CLEAR + std::cout << "Test KLU with Rf refactorization and IR " << RED << "FAILED" << CLEAR << ", error sum: " << error_sum << std::endl; } From c3df4abb340f60b8e8cb9216ccaf6045fc6e6ccd Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Fri, 4 Oct 2024 20:23:52 -0400 Subject: [PATCH 03/13] Fix number of digits in test output. --- tests/functionality/testKLU.cpp | 6 ++++-- tests/functionality/testKLU_RocSolver.cpp | 10 ++++++---- tests/functionality/testLUSOL.cpp | 6 ++++-- tests/functionality/testSysGLU.cpp | 7 +++++-- tests/functionality/testSysRefactor.cpp | 7 +++++-- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/functionality/testKLU.cpp b/tests/functionality/testKLU.cpp index 5c5745e3..54501050 100644 --- a/tests/functionality/testKLU.cpp +++ b/tests/functionality/testKLU.cpp @@ -131,8 +131,9 @@ int main(int argc, char *argv[]) real_type normRmatrix1CPU = sqrt(vector_handler->dot(vec_r, vec_r, ReSolve::memory::HOST)); std::cout<<"Results (first matrix): "<dot(vec_r, vec_r, ReSolve::memory::HOST)); std::cout<<"Results (second matrix): "<dot(vec_r, vec_r, ReSolve::memory::DEVICE)); std::cout<<"Results (first matrix): "<dot(vec_r, vec_r, ReSolve::memory::DEVICE)); std::cout<<"Results (second matrix): "< 10.0*std::numeric_limits::epsilon()) { - std::cout << "Relative residual norm computation failed:\n" << std::setprecision(16) + std::cout << "Relative residual norm computation failed:\n" + << std::scientific << std::setprecision(16) << "\tTest value : " << normRmatrix1/normB1 << "\n" << "\tSystemSolver computed : " << rel_residual_norm << "\n\n"; error_sum++; @@ -271,13 +272,15 @@ int main(int argc, char *argv[]) rel_residual_norm = solver.getResidualNorm(vec_rhs, vec_x); error = std::abs(normB2 * rel_residual_norm - normRmatrix2)/normRmatrix2; if (error > 10.0*std::numeric_limits::epsilon()) { - std::cout << "Relative residual norm computation failed:\n" << std::setprecision(16) + std::cout << "Relative residual norm computation failed:\n" + << std::scientific << std::setprecision(16) << "\tTest value : " << normRmatrix2/normB2 << "\n" << "\tSystemSolver computed : " << rel_residual_norm << "\n\n"; error_sum++; } std::cout << "Results (second matrix): " << std::endl << std::endl; + std::cout << std::scientific << std::setprecision(16); std::cout << "\t ||b-A*x||_2 : " << normRmatrix2 << " (residual norm)\n"; std::cout << "\t ||b-A*x||_2/||b||_2 : " << normRmatrix2/normB2 << " (relative residual norm)\n"; std::cout << "\t ||b-A*x||/(||A||*||x||) : " << nsr_norm << " (norm of scaled residuals)\n"; diff --git a/tests/functionality/testSysRefactor.cpp b/tests/functionality/testSysRefactor.cpp index e346e942..0de3bae7 100644 --- a/tests/functionality/testSysRefactor.cpp +++ b/tests/functionality/testSysRefactor.cpp @@ -197,7 +197,8 @@ int main(int argc, char *argv[]) real_type rel_residual_norm = solver.getResidualNorm(vec_rhs, vec_x); error = std::abs(normB1 * rel_residual_norm - normRmatrix1)/normRmatrix1; if (error > 10.0*std::numeric_limits::epsilon()) { - std::cout << "Relative residual norm computation failed:\n" << std::setprecision(16) + std::cout << "Relative residual norm computation failed:\n"; + std::cout << std::scientific << std::setprecision(16) << "\tTest value : " << normRmatrix1/normB1 << "\n" << "\tSystemSolver computed : " << rel_residual_norm << "\n\n"; error_sum++; @@ -291,7 +292,8 @@ int main(int argc, char *argv[]) rel_residual_norm = solver.getResidualNorm(vec_rhs, vec_x); error = std::abs(normB2 * rel_residual_norm - normRmatrix2)/normRmatrix2; if (error > 10.0*std::numeric_limits::epsilon()) { - std::cout << "Relative residual norm computation failed:\n" << std::setprecision(16) + std::cout << "Relative residual norm computation failed:\n"; + std::cout << std::scientific << std::setprecision(16) << "\tTest value : " << normRmatrix2/normB2 << "\n" << "\tSystemSolver computed : " << rel_residual_norm << "\n\n"; error_sum++; @@ -309,6 +311,7 @@ int main(int argc, char *argv[]) std::cout << "Results (second matrix): " << std::endl << std::endl; + std::cout << std::scientific << std::setprecision(16); std::cout << "\t ||b-A*x||_2 : " << normRmatrix2 << " (residual norm)\n"; std::cout << "\t ||b-A*x||_2/||b||_2 : " << normRmatrix2/normB2 << " (relative residual norm)\n"; std::cout << "\t ||x-x_true||_2 : " << normDiffMatrix2 << " (solution error)\n"; From 7d088f827c7113cf22587f17a90be3e3d9a8b7dc Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Wed, 22 Jan 2025 21:57:37 +0000 Subject: [PATCH 04/13] Fix compiler warnings. --- examples/r_KLU_GLU.cpp | 8 ++++---- examples/r_KLU_GLU_matrix_values_update.cpp | 10 +++++----- examples/r_KLU_KLU.cpp | 8 ++++---- examples/r_KLU_KLU_standalone.cpp | 8 ++++---- examples/r_KLU_cusolverrf_redo_factorization.cpp | 14 +++++++------- examples/r_KLU_rf.cpp | 8 ++++---- examples/r_KLU_rf_FGMRES.cpp | 8 ++++---- examples/r_KLU_rf_FGMRES_reuse_factorization.cpp | 12 ++++++------ examples/r_KLU_rocSolverRf_FGMRES.cpp | 8 ++++---- examples/r_KLU_rocsolverrf.cpp | 8 ++++---- examples/r_KLU_rocsolverrf_redo_factorization.cpp | 10 +++++----- examples/r_SysSolver.cpp | 8 ++++---- examples/r_SysSolverCuda.cpp | 6 +++--- examples/r_SysSolverHip.cpp | 2 +- examples/r_SysSolverHipRefine.cpp | 2 +- examples/r_randGMRES.cpp | 8 ++++---- examples/r_randGMRES_CUDA.cpp | 8 ++++---- examples/r_randGMRES_cpu.cpp | 8 ++++---- resolve/LinSolverDirectCpuILU0.cpp | 2 +- resolve/LinSolverDirectCuSolverGLU.cpp | 2 +- resolve/LinSolverDirectCuSolverRf.cpp | 6 +++--- resolve/LinSolverDirectCuSparseILU0.cpp | 2 +- resolve/LinSolverDirectKLU.cpp | 2 +- resolve/LinSolverDirectLUSOL.cpp | 2 +- resolve/LinSolverDirectSerialILU0.cpp | 2 +- resolve/matrix/MatrixHandlerCpu.cpp | 8 ++++---- 26 files changed, 85 insertions(+), 85 deletions(-) diff --git a/examples/r_KLU_GLU.cpp b/examples/r_KLU_GLU.cpp index 89e9cb61..5c7ffcec 100644 --- a/examples/r_KLU_GLU.cpp +++ b/examples/r_KLU_GLU.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCUDA* workspace_CUDA = new ReSolve::LinAlgWorkspaceCUDA; workspace_CUDA->initializeHandles(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_CUDA); @@ -43,9 +43,9 @@ int main(int argc, char *argv[]) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; real_type norm_A, norm_x, norm_r;//used for INF norm ReSolve::LinSolverDirectKLU* KLU = new ReSolve::LinSolverDirectKLU; diff --git a/examples/r_KLU_GLU_matrix_values_update.cpp b/examples/r_KLU_GLU_matrix_values_update.cpp index ca073dfa..06343f51 100644 --- a/examples/r_KLU_GLU_matrix_values_update.cpp +++ b/examples/r_KLU_GLU_matrix_values_update.cpp @@ -37,8 +37,8 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; - ReSolve::matrix::Csr* A_exp; + ReSolve::matrix::Csr* A = nullptr; + ReSolve::matrix::Csr* A_exp = nullptr; ReSolve::LinAlgWorkspaceCUDA* workspace_CUDA = new ReSolve::LinAlgWorkspaceCUDA; workspace_CUDA->initializeHandles(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_CUDA); @@ -46,9 +46,9 @@ int main(int argc, char *argv[]) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::LinSolverDirectKLU* KLU = new ReSolve::LinSolverDirectKLU; ReSolve::LinSolverDirectCuSolverGLU* GLU = new ReSolve::LinSolverDirectCuSolverGLU(workspace_CUDA); diff --git a/examples/r_KLU_KLU.cpp b/examples/r_KLU_KLU.cpp index 12672391..743b31fd 100644 --- a/examples/r_KLU_KLU.cpp +++ b/examples/r_KLU_KLU.cpp @@ -35,16 +35,16 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCpu* workspace = new ReSolve::LinAlgWorkspaceCpu(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace); ReSolve::VectorHandler* vector_handler = new ReSolve::VectorHandler(workspace); real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; real_type norm_A, norm_x, norm_r;//used for INF norm ReSolve::LinSolverDirectKLU* KLU = new ReSolve::LinSolverDirectKLU; diff --git a/examples/r_KLU_KLU_standalone.cpp b/examples/r_KLU_KLU_standalone.cpp index df84fb34..8be2d1e4 100644 --- a/examples/r_KLU_KLU_standalone.cpp +++ b/examples/r_KLU_KLU_standalone.cpp @@ -31,16 +31,16 @@ int main(int argc, char *argv[]) std::string fileId; std::string rhsId; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCpu* workspace = new ReSolve::LinAlgWorkspaceCpu(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace); ReSolve::VectorHandler* vector_handler = new ReSolve::VectorHandler(workspace); real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::LinSolverDirectKLU* KLU = new ReSolve::LinSolverDirectKLU; diff --git a/examples/r_KLU_cusolverrf_redo_factorization.cpp b/examples/r_KLU_cusolverrf_redo_factorization.cpp index 0b97b0de..33475f3c 100644 --- a/examples/r_KLU_cusolverrf_redo_factorization.cpp +++ b/examples/r_KLU_cusolverrf_redo_factorization.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[] ) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCUDA* workspace_CUDA = new ReSolve::LinAlgWorkspaceCUDA; workspace_CUDA->initializeHandles(); @@ -44,15 +44,15 @@ int main(int argc, char *argv[] ) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::LinSolverDirectKLU* KLU = new ReSolve::LinSolverDirectKLU; ReSolve::LinSolverDirectCuSolverRf* Rf = new ReSolve::LinSolverDirectCuSolverRf(); - real_type res_nrm; - real_type b_nrm; + real_type res_nrm = 0.0; + real_type b_nrm = 0.0; // We need them. They hold a POINTER. Don't delete them here. KLU deletes them. ReSolve::matrix::Csc* L_csc; @@ -60,7 +60,7 @@ int main(int argc, char *argv[] ) index_type* P; index_type* Q; - int status; + int status = 0; int status_refactor = 0; for (int i = 0; i < numSystems; ++i) { diff --git a/examples/r_KLU_rf.cpp b/examples/r_KLU_rf.cpp index 2e6e90ba..e05c0f3f 100644 --- a/examples/r_KLU_rf.cpp +++ b/examples/r_KLU_rf.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[] ) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCUDA* workspace_CUDA = new ReSolve::LinAlgWorkspaceCUDA; workspace_CUDA->initializeHandles(); @@ -44,9 +44,9 @@ int main(int argc, char *argv[] ) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::LinSolverDirectKLU* KLU = new ReSolve::LinSolverDirectKLU; ReSolve::LinSolverDirectCuSolverRf* Rf = new ReSolve::LinSolverDirectCuSolverRf; diff --git a/examples/r_KLU_rf_FGMRES.cpp b/examples/r_KLU_rf_FGMRES.cpp index f9785a13..3e0722cf 100644 --- a/examples/r_KLU_rf_FGMRES.cpp +++ b/examples/r_KLU_rf_FGMRES.cpp @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCUDA* workspace_CUDA = new ReSolve::LinAlgWorkspaceCUDA; workspace_CUDA->initializeHandles(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_CUDA); @@ -44,9 +44,9 @@ int main(int argc, char *argv[]) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; real_type norm_A, norm_x, norm_r;//used for INF norm ReSolve::GramSchmidt* GS = new ReSolve::GramSchmidt(vector_handler, ReSolve::GramSchmidt::CGS2); diff --git a/examples/r_KLU_rf_FGMRES_reuse_factorization.cpp b/examples/r_KLU_rf_FGMRES_reuse_factorization.cpp index 5ef48aef..9c3bd60f 100644 --- a/examples/r_KLU_rf_FGMRES_reuse_factorization.cpp +++ b/examples/r_KLU_rf_FGMRES_reuse_factorization.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCUDA* workspace_CUDA = new ReSolve::LinAlgWorkspaceCUDA; workspace_CUDA->initializeHandles(); @@ -46,9 +46,9 @@ int main(int argc, char *argv[]) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::GramSchmidt* GS = new ReSolve::GramSchmidt(vector_handler, ReSolve::GramSchmidt::CGS2); @@ -121,8 +121,8 @@ int main(int argc, char *argv[]) } std::cout << "CSR matrix loaded. Expanded NNZ: " << A->getNnz() << std::endl; - //Now call direct solver - int status; + // Now call direct solver + int status = 0; real_type norm_b; if (i < 2){ KLU->setup(A); diff --git a/examples/r_KLU_rocSolverRf_FGMRES.cpp b/examples/r_KLU_rocSolverRf_FGMRES.cpp index fb85c45a..be6e17dd 100644 --- a/examples/r_KLU_rocSolverRf_FGMRES.cpp +++ b/examples/r_KLU_rocSolverRf_FGMRES.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceHIP* workspace_HIP = new ReSolve::LinAlgWorkspaceHIP(); workspace_HIP->initializeHandles(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_HIP); @@ -45,9 +45,9 @@ int main(int argc, char *argv[]) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; real_type norm_A; real_type norm_x; real_type norm_r; diff --git a/examples/r_KLU_rocsolverrf.cpp b/examples/r_KLU_rocsolverrf.cpp index d7774131..f2d05d12 100644 --- a/examples/r_KLU_rocsolverrf.cpp +++ b/examples/r_KLU_rocsolverrf.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceHIP* workspace_HIP = new ReSolve::LinAlgWorkspaceHIP; workspace_HIP->initializeHandles(); @@ -44,9 +44,9 @@ int main(int argc, char *argv[]) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; real_type norm_A, norm_x, norm_r; //used for INF norm diff --git a/examples/r_KLU_rocsolverrf_redo_factorization.cpp b/examples/r_KLU_rocsolverrf_redo_factorization.cpp index ca3e7017..65b67de2 100644 --- a/examples/r_KLU_rocsolverrf_redo_factorization.cpp +++ b/examples/r_KLU_rocsolverrf_redo_factorization.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[] ) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceHIP* workspace_HIP = new ReSolve::LinAlgWorkspaceHIP; workspace_HIP->initializeHandles(); @@ -44,9 +44,9 @@ int main(int argc, char *argv[] ) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::LinSolverDirectKLU* KLU = new ReSolve::LinSolverDirectKLU; ReSolve::LinSolverDirectRocSolverRf* Rf = new ReSolve::LinSolverDirectRocSolverRf(workspace_HIP); @@ -116,7 +116,7 @@ int main(int argc, char *argv[] ) std::cout << "CSR matrix loaded. Expanded NNZ: " << A->getNnz() << std::endl; //Now call direct solver - int status; + int status = 0; if (i < 2){ KLU->setup(A); status = KLU->analyze(); diff --git a/examples/r_SysSolver.cpp b/examples/r_SysSolver.cpp index 613cb708..62e8e5bd 100644 --- a/examples/r_SysSolver.cpp +++ b/examples/r_SysSolver.cpp @@ -36,16 +36,16 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCpu* workspace = new ReSolve::LinAlgWorkspaceCpu(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace); ReSolve::VectorHandler* vector_handler = new ReSolve::VectorHandler(workspace); real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::SystemSolver* solver = new ReSolve::SystemSolver(workspace); diff --git a/examples/r_SysSolverCuda.cpp b/examples/r_SysSolverCuda.cpp index b939abd8..58b68388 100644 --- a/examples/r_SysSolverCuda.cpp +++ b/examples/r_SysSolverCuda.cpp @@ -35,15 +35,15 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCUDA* workspace_CUDA = new ReSolve::LinAlgWorkspaceCUDA; workspace_CUDA->initializeHandles(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_CUDA); real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; ReSolve::SystemSolver* solver = new ReSolve::SystemSolver(workspace_CUDA); diff --git a/examples/r_SysSolverHip.cpp b/examples/r_SysSolverHip.cpp index 8bb00a82..5cbd8dae 100644 --- a/examples/r_SysSolverHip.cpp +++ b/examples/r_SysSolverHip.cpp @@ -36,7 +36,7 @@ int main(int argc, char *argv[] ) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceHIP* workspace_HIP = new ReSolve::LinAlgWorkspaceHIP(); workspace_HIP->initializeHandles(); diff --git a/examples/r_SysSolverHipRefine.cpp b/examples/r_SysSolverHipRefine.cpp index 6a68149a..c78b1f34 100644 --- a/examples/r_SysSolverHipRefine.cpp +++ b/examples/r_SysSolverHipRefine.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) std::string matrixFileNameFull; std::string rhsFileNameFull; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceHIP* workspace_HIP = new ReSolve::LinAlgWorkspaceHIP(); workspace_HIP->initializeHandles(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_HIP); diff --git a/examples/r_randGMRES.cpp b/examples/r_randGMRES.cpp index c4ebffa1..a2c621c7 100644 --- a/examples/r_randGMRES.cpp +++ b/examples/r_randGMRES.cpp @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) std::string rhsFileName = argv[2]; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceHIP* workspace_HIP = new ReSolve::LinAlgWorkspaceHIP(); workspace_HIP->initializeHandles(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_HIP); @@ -34,9 +34,9 @@ int main(int argc, char *argv[]) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::GramSchmidt* GS = new ReSolve::GramSchmidt(vector_handler, ReSolve::GramSchmidt::CGS2); diff --git a/examples/r_randGMRES_CUDA.cpp b/examples/r_randGMRES_CUDA.cpp index 68d48360..c7e837d2 100644 --- a/examples/r_randGMRES_CUDA.cpp +++ b/examples/r_randGMRES_CUDA.cpp @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) std::string matrixFileName = argv[1]; std::string rhsFileName = argv[2]; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCUDA* workspace_CUDA = new ReSolve::LinAlgWorkspaceCUDA(); workspace_CUDA->initializeHandles(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_CUDA); @@ -33,9 +33,9 @@ int main(int argc, char *argv[]) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::GramSchmidt* GS = new ReSolve::GramSchmidt(vector_handler, ReSolve::GramSchmidt::CGS2); diff --git a/examples/r_randGMRES_cpu.cpp b/examples/r_randGMRES_cpu.cpp index 68b78f5c..5a2c046d 100644 --- a/examples/r_randGMRES_cpu.cpp +++ b/examples/r_randGMRES_cpu.cpp @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) std::string matrixFileName = argv[1]; std::string rhsFileName = argv[2]; - ReSolve::matrix::Csr* A; + ReSolve::matrix::Csr* A = nullptr; ReSolve::LinAlgWorkspaceCpu* workspace_Cpu = new ReSolve::LinAlgWorkspaceCpu(); workspace_Cpu->initializeHandles(); ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_Cpu); @@ -33,9 +33,9 @@ int main(int argc, char *argv[]) real_type* rhs = nullptr; real_type* x = nullptr; - vector_type* vec_rhs; - vector_type* vec_x; - vector_type* vec_r; + vector_type* vec_rhs = nullptr; + vector_type* vec_x = nullptr; + vector_type* vec_r = nullptr; ReSolve::GramSchmidt* GS = new ReSolve::GramSchmidt(vector_handler, ReSolve::GramSchmidt::MGS); diff --git a/resolve/LinSolverDirectCpuILU0.cpp b/resolve/LinSolverDirectCpuILU0.cpp index 20f8d906..0b470c4e 100644 --- a/resolve/LinSolverDirectCpuILU0.cpp +++ b/resolve/LinSolverDirectCpuILU0.cpp @@ -347,7 +347,7 @@ namespace ReSolve return 0; } - int LinSolverDirectCpuILU0::setCliParam(const std::string id, const std::string value) + int LinSolverDirectCpuILU0::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) { diff --git a/resolve/LinSolverDirectCuSolverGLU.cpp b/resolve/LinSolverDirectCuSolverGLU.cpp index 0bd5dd28..bfa182a6 100644 --- a/resolve/LinSolverDirectCuSolverGLU.cpp +++ b/resolve/LinSolverDirectCuSolverGLU.cpp @@ -200,7 +200,7 @@ namespace ReSolve return 1; } - int LinSolverDirectCuSolverGLU::setCliParam(const std::string id, const std::string value) + int LinSolverDirectCuSolverGLU::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) { diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index 70364c21..a1c9eeaf 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -156,12 +156,12 @@ namespace ReSolve double zero = static_cast(nzero); double boost = static_cast(nboost); status_cusolverrf_ = cusolverRfSetNumericProperties(handle_cusolverrf_, - nzero, - nboost); + zero, + boost); return status_cusolverrf_; } - int LinSolverDirectCuSolverRf::setCliParam(const std::string id, const std::string value) + int LinSolverDirectCuSolverRf::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) { diff --git a/resolve/LinSolverDirectCuSparseILU0.cpp b/resolve/LinSolverDirectCuSparseILU0.cpp index 0e38d1dc..a583d031 100644 --- a/resolve/LinSolverDirectCuSparseILU0.cpp +++ b/resolve/LinSolverDirectCuSparseILU0.cpp @@ -313,7 +313,7 @@ namespace ReSolve return error_sum; } - int LinSolverDirectCuSparseILU0::setCliParam(const std::string id, const std::string value) + int LinSolverDirectCuSparseILU0::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) { diff --git a/resolve/LinSolverDirectKLU.cpp b/resolve/LinSolverDirectKLU.cpp index a45f00eb..b916228c 100644 --- a/resolve/LinSolverDirectKLU.cpp +++ b/resolve/LinSolverDirectKLU.cpp @@ -287,7 +287,7 @@ namespace ReSolve return Common_.rcond; } - int LinSolverDirectKLU::setCliParam(const std::string id, const std::string value) + int LinSolverDirectKLU::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) { diff --git a/resolve/LinSolverDirectLUSOL.cpp b/resolve/LinSolverDirectLUSOL.cpp index 3d31cb35..171edb21 100644 --- a/resolve/LinSolverDirectLUSOL.cpp +++ b/resolve/LinSolverDirectLUSOL.cpp @@ -473,7 +473,7 @@ namespace ReSolve return 0; } - int LinSolverDirectLUSOL::setCliParam(const std::string id, const std::string value) + int LinSolverDirectLUSOL::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) { diff --git a/resolve/LinSolverDirectSerialILU0.cpp b/resolve/LinSolverDirectSerialILU0.cpp index 2e9bc4cb..6082ceca 100644 --- a/resolve/LinSolverDirectSerialILU0.cpp +++ b/resolve/LinSolverDirectSerialILU0.cpp @@ -239,7 +239,7 @@ namespace ReSolve return error_sum; } - int LinSolverDirectSerialILU0::setCliParam(const std::string id, const std::string value) + int LinSolverDirectSerialILU0::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) { diff --git a/resolve/matrix/MatrixHandlerCpu.cpp b/resolve/matrix/MatrixHandlerCpu.cpp index 63366d31..58625ba6 100644 --- a/resolve/matrix/MatrixHandlerCpu.cpp +++ b/resolve/matrix/MatrixHandlerCpu.cpp @@ -107,12 +107,12 @@ namespace ReSolve { assert(A->getSparseFormat() == matrix::Sparse::COMPRESSED_SPARSE_ROW && "Matrix has to be in CSR format for matrix-vector product.\n"); - real_type sum, nrm; - index_type i, j; + real_type sum = 0.0; + real_type nrm = 0.0; - for (i = 0; i < A->getNumRows(); ++i) { + for (index_type i = 0; i < A->getNumRows(); ++i) { sum = 0.0; - for (j = A->getRowData(memory::HOST)[i]; j < A->getRowData(memory::HOST)[i+1]; ++j) { + for (index_type j = A->getRowData(memory::HOST)[i]; j < A->getRowData(memory::HOST)[i+1]; ++j) { sum += std::abs(A->getValues(memory::HOST)[j]); } if (i == 0) { From 921378fcf95399b314b95400eb64b76443f016d7 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Thu, 23 Jan 2025 01:49:39 +0000 Subject: [PATCH 05/13] Implement CLI parameter setting for KLU. --- resolve/LinSolverDirect.cpp | 21 ------------- resolve/LinSolverDirect.hpp | 9 ------ resolve/LinSolverDirectKLU.cpp | 54 +++++++++++++++++++++++++++++----- resolve/LinSolverDirectKLU.hpp | 44 ++++++++++++++++++++++++--- 4 files changed, 87 insertions(+), 41 deletions(-) diff --git a/resolve/LinSolverDirect.cpp b/resolve/LinSolverDirect.cpp index bc40bdc1..3737cf60 100644 --- a/resolve/LinSolverDirect.cpp +++ b/resolve/LinSolverDirect.cpp @@ -76,25 +76,4 @@ namespace ReSolve return nullptr; } - void LinSolverDirect::setPivotThreshold(real_type tol) - { - pivot_threshold_tol_ = tol; - } - - void LinSolverDirect::setOrdering(int ordering) - { - ordering_ = ordering; - } - - void LinSolverDirect::setHaltIfSingular(bool is_halt) - { - halt_if_singular_ = is_halt; - } - - real_type LinSolverDirect::getMatrixConditionNumber() - { - out::error() << "Solver does not implement returning system matrix condition number.\n"; - return -1.0; - } - } // namespace ReSolve diff --git a/resolve/LinSolverDirect.hpp b/resolve/LinSolverDirect.hpp index d41b325d..e5aea729 100644 --- a/resolve/LinSolverDirect.hpp +++ b/resolve/LinSolverDirect.hpp @@ -35,21 +35,12 @@ namespace ReSolve virtual index_type* getPOrdering(); virtual index_type* getQOrdering(); - virtual void setPivotThreshold(real_type tol); - virtual void setOrdering(int ordering); - virtual void setHaltIfSingular(bool is_halt); - - virtual real_type getMatrixConditionNumber(); - protected: matrix::Sparse* L_{nullptr}; matrix::Sparse* U_{nullptr}; index_type* P_{nullptr}; index_type* Q_{nullptr}; - int ordering_{1}; // 0 = AMD, 1 = COLAMD, 2 = user provided P, Q - real_type pivot_threshold_tol_{0.1}; - bool halt_if_singular_{false}; }; } diff --git a/resolve/LinSolverDirectKLU.cpp b/resolve/LinSolverDirectKLU.cpp index b916228c..11191e03 100644 --- a/resolve/LinSolverDirectKLU.cpp +++ b/resolve/LinSolverDirectKLU.cpp @@ -24,6 +24,9 @@ namespace ReSolve Common_.tol = pivot_threshold_tol_; Common_.halt_if_singular = halt_if_singular_; + // Register configurable parameters + initParamList(); + out::summary() << "KLU solver set with parameters:\n" << "\tbtf = " << Common_.btf << "\n" << "\tscale = " << Common_.scale << "\n" @@ -65,8 +68,10 @@ namespace ReSolve if (Symbolic_ != nullptr) { klu_free_symbolic(&Symbolic_, &Common_); } - Symbolic_ = klu_analyze(A_->getNumRows(), A_->getRowData(memory::HOST), A_->getColData(memory::HOST), &Common_) ; - + Symbolic_ = klu_analyze(A_->getNumRows(), + A_->getRowData(memory::HOST), + A_->getColData(memory::HOST), + &Common_); factors_extracted_ = false; if (L_ != nullptr) { @@ -80,7 +85,7 @@ namespace ReSolve } if (Symbolic_ == nullptr) { - out::error() << "Symbolic_ factorization crashed with Common_.status = " + out::error() << "Symbolic_ factorization failed with Common_.status = " << Common_.status << "\n"; return 1; } @@ -287,10 +292,19 @@ namespace ReSolve return Common_.rcond; } - int LinSolverDirectKLU::setCliParam(const std::string id, const std::string /* value */) + int LinSolverDirectKLU::setCliParam(const std::string id, const std::string value) { switch (getParamId(id)) { + case PIVOT_TOL: + setPivotThreshold(atof(value.c_str())); + break; + case ORDERING: + setOrdering(atoi(value.c_str())); + break; + case HALT_IF_SINGULAR: + setHaltIfSingular(value == "yes"); + break; default: std::cout << "Setting parameter failed!\n"; } @@ -311,6 +325,8 @@ namespace ReSolve { switch (getParamId(id)) { + case ORDERING: + return ordering_; default: out::error() << "Trying to get unknown integer parameter " << id << "\n"; } @@ -321,6 +337,8 @@ namespace ReSolve { switch (getParamId(id)) { + case PIVOT_TOL: + return pivot_threshold_tol_; default: out::error() << "Trying to get unknown real parameter " << id << "\n"; } @@ -331,6 +349,8 @@ namespace ReSolve { switch (getParamId(id)) { + case HALT_IF_SINGULAR: + return halt_if_singular_; default: out::error() << "Trying to get unknown boolean parameter " << id << "\n"; } @@ -341,11 +361,31 @@ namespace ReSolve { switch (getParamId(id)) { - default: - out::error() << "Trying to print unknown parameter " << id << "\n"; - return 1; + case PIVOT_TOL: + std::cout << pivot_threshold_tol_ << "\n"; + break; + case ORDERING: + std::cout << ordering_ << "\n"; + break; + case HALT_IF_SINGULAR: + std::cout << halt_if_singular_ << "\n"; + break; + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; } return 0; } + // + // Private methods + // + + void LinSolverDirectKLU::initParamList() + { + params_list_["pivot_tol"] = PIVOT_TOL; + params_list_["ordering"] = ORDERING; + params_list_["halt_if_singular"] = HALT_IF_SINGULAR; + } + } // namespace ReSolve diff --git a/resolve/LinSolverDirectKLU.hpp b/resolve/LinSolverDirectKLU.hpp index 8024065b..8336c979 100644 --- a/resolve/LinSolverDirectKLU.hpp +++ b/resolve/LinSolverDirectKLU.hpp @@ -45,11 +45,11 @@ namespace ReSolve index_type* getPOrdering() override; index_type* getQOrdering() override; - virtual void setPivotThreshold(real_type tol) override; - virtual void setOrdering(int ordering) override; - virtual void setHaltIfSingular(bool isHalt) override; + virtual void setPivotThreshold(real_type tol); + virtual void setOrdering(int ordering); + virtual void setHaltIfSingular(bool isHalt); - virtual real_type getMatrixConditionNumber() override; + virtual real_type getMatrixConditionNumber(); int setCliParam(const std::string id, const std::string value) override; std::string getCliParamString(const std::string id) const override; @@ -59,6 +59,42 @@ namespace ReSolve int printCliParam(const std::string id) const override; private: + enum ParamaterIDs {PIVOT_TOL=0, ORDERING, HALT_IF_SINGULAR}; + + /** + * @brief Ordering type (during the analysis) + * + * Available values are 0 = AMD, 1 = COLAMD, 2 = user provided P, Q. + * + * Default is COLAMD. + */ + int ordering_{1}; + + /** + * @brief Partial pivoing tolerance. + * + * If the diagonal entry has a magnitude greater than or equal to tol + * times the largest magnitude of entries in the pivot column, then the + * diagonal entry is chosen. + */ + real_type pivot_threshold_tol_{0.1}; + + /** + * @brief Halt if matrix is singular. + * + * If false: keep going. Return a Numeric object with a zero U(k,k). + * A divide-by-zero may occur when computing L(:,k). The Numeric object + * can be passed to klu_solve (a divide-by-zero will occur). It can + * also be safely passed to refactorization methods. + * + * If true: stop quickly. klu_factor will free the partially-constructed + * Numeric object. klu_refactor will not free it, but will leave the + * numerical values only partially defined. + */ + bool halt_if_singular_{false}; + + private: + void initParamList(); bool factors_extracted_{false}; klu_common Common_; //settings klu_symbolic* Symbolic_{nullptr}; From 8fc24695e8dc79355ce4f3fc0243879946fe0f50 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Thu, 23 Jan 2025 02:24:42 +0000 Subject: [PATCH 06/13] Parameter settings for cusolverRf. --- resolve/LinSolverDirectCuSolverRf.cpp | 39 +++++++++++++++++++++++---- resolve/LinSolverDirectCuSolverRf.hpp | 10 ++++--- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index a1c9eeaf..27ae4712 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -10,6 +10,7 @@ namespace ReSolve { cusolverRfCreate(&handle_cusolverrf_); setup_completed_ = false; + initParamList(); } LinSolverDirectCuSolverRf::~LinSolverDirectCuSolverRf() @@ -161,10 +162,18 @@ namespace ReSolve return status_cusolverrf_; } - int LinSolverDirectCuSolverRf::setCliParam(const std::string id, const std::string /* value */) + int LinSolverDirectCuSolverRf::setCliParam(const std::string id, const std::string value) { switch (getParamId(id)) { + case ZERO_PIVOT: + zero_pivot_ = atof(value.c_str()); + setNumericalProperties(zero_pivot_, pivot_boost_); + break; + case PIVOT_BOOST: + pivot_boost_ = atof(value.c_str()); + setNumericalProperties(zero_pivot_, pivot_boost_); + break; default: std::cout << "Setting parameter failed!\n"; } @@ -195,6 +204,10 @@ namespace ReSolve { switch (getParamId(id)) { + case ZERO_PIVOT: + return zero_pivot_; + case PIVOT_BOOST: + return pivot_boost_; default: out::error() << "Trying to get unknown real parameter " << id << "\n"; } @@ -215,11 +228,27 @@ namespace ReSolve { switch (getParamId(id)) { - default: - out::error() << "Trying to print unknown parameter " << id << "\n"; - return 1; + case ZERO_PIVOT: + std::cout << zero_pivot_ << "\n"; + break; + case PIVOT_BOOST: + std::cout << pivot_boost_ << "\n"; + break; + default: + out::error() << "Trying to print unknown parameter " << id << "\n"; + return 1; } return 0; } -}// namespace resolve + // + // Private methods + // + + void LinSolverDirectCuSolverRf::initParamList() + { + params_list_["zero_pivot"] = ZERO_PIVOT; + params_list_["pivot_boost"] = PIVOT_BOOST; + } + +} // namespace resolve diff --git a/resolve/LinSolverDirectCuSolverRf.hpp b/resolve/LinSolverDirectCuSolverRf.hpp index 4c069f6d..70f2d527 100644 --- a/resolve/LinSolverDirectCuSolverRf.hpp +++ b/resolve/LinSolverDirectCuSolverRf.hpp @@ -54,6 +54,13 @@ namespace ReSolve int printCliParam(const std::string id) const override; private: + enum ParamaterIDs {ZERO_PIVOT=0, PIVOT_BOOST}; + real_type zero_pivot_{0.0}; ///< The value below which zero pivot is flagged. + real_type pivot_boost_{0.0}; ///< The value which is substituted for zero pivot. + + private: + void initParamList(); + cusolverRfHandle_t handle_cusolverrf_; cusolverStatus_t status_cusolverrf_; @@ -62,9 +69,6 @@ namespace ReSolve real_type* d_T_{nullptr}; bool setup_completed_{false}; - real_type zero_pivot_{0.0}; ///< The value below which zero pivot is flagged. - real_type pivot_boost_{0.0}; ///< The value which is substituted for zero pivot. - MemoryHandler mem_; ///< Device memory manager object }; } From ccb105a38be0508caae8e07851b29b7e85b43ed9 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Thu, 23 Jan 2025 12:45:41 -0500 Subject: [PATCH 07/13] Fix LUSOL build bug. --- resolve/LinSolverDirectLUSOL.cpp | 27 +-------------------------- resolve/LinSolverDirectLUSOL.hpp | 6 ------ 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/resolve/LinSolverDirectLUSOL.cpp b/resolve/LinSolverDirectLUSOL.cpp index 171edb21..9fb6741c 100644 --- a/resolve/LinSolverDirectLUSOL.cpp +++ b/resolve/LinSolverDirectLUSOL.cpp @@ -43,7 +43,7 @@ namespace ReSolve luparm_[2] = 5; // Pivoting type - // luparm_[5] = 0 => TPP: Threshold Partial Pivoting. 0 + // luparm_[5] = 0 => TPP: Threshold Partial Pivoting. // = 1 => TRP: Threshold Rook Pivoting. // = 2 => TCP: Threshold Complete Pivoting. // = 3 => TSP: Threshold Symmetric Pivoting. @@ -448,31 +448,6 @@ namespace ReSolve return Q_; } - void LinSolverDirectLUSOL::setPivotThreshold(real_type /* _ */) - { - out::error() << "LinSolverDirect::setPivotThreshold(real_type) called on " - "LinSolverDirectLUSOL on which it is irrelevant!\n"; - } - - void LinSolverDirectLUSOL::setOrdering(int /* _ */) - { - out::error() << "LinSolverDirect::setOrdering(int) called on " - "LinSolverDirectLUSOL on which it is irrelevant!\n"; - } - - void LinSolverDirectLUSOL::setHaltIfSingular(bool /* _ */) - { - out::error() << "LinSolverDirect::setHaltIfSingular(bool) called on " - "LinSolverDirectLUSOL on which it is irrelevant!\n"; - } - - real_type LinSolverDirectLUSOL::getMatrixConditionNumber() - { - out::error() << "LinSolverDirect::getMatrixConditionNumber() called on " - "LinSolverDirectLUSOL which is unimplemented!\n"; - return 0; - } - int LinSolverDirectLUSOL::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) diff --git a/resolve/LinSolverDirectLUSOL.hpp b/resolve/LinSolverDirectLUSOL.hpp index df3cf6fd..9de68927 100644 --- a/resolve/LinSolverDirectLUSOL.hpp +++ b/resolve/LinSolverDirectLUSOL.hpp @@ -58,12 +58,6 @@ namespace ReSolve index_type* getPOrdering() override; index_type* getQOrdering() override; - virtual void setPivotThreshold(real_type tol) override; - virtual void setOrdering(int ordering) override; - virtual void setHaltIfSingular(bool isHalt) override; - - virtual real_type getMatrixConditionNumber() override; - int setCliParam(const std::string id, const std::string value) override; std::string getCliParamString(const std::string id) const override; index_type getCliParamInt(const std::string id) const override; From a4300d8c312d4ba746685249e72b18880d3edb24 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Thu, 23 Jan 2025 21:45:33 +0000 Subject: [PATCH 08/13] fixed minor typos --- resolve/LinSolver.hpp | 6 +++--- resolve/LinSolverDirectCuSolverRf.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resolve/LinSolver.hpp b/resolve/LinSolver.hpp index f04d8109..ae35ca70 100644 --- a/resolve/LinSolver.hpp +++ b/resolve/LinSolver.hpp @@ -49,10 +49,10 @@ namespace ReSolve real_type evaluateResidual(); virtual int setCliParam(const std::string /* id */, const std::string /* value */) = 0; - virtual std::string getCliParamString(const std::string /* id */) const = 0; + virtual std::string getCliParamString(const std::string /* id */) const = ""; virtual index_type getCliParamInt(const std::string /* id */) const = 0; - virtual real_type getCliParamReal(const std::string /* id */) const = 0; - virtual bool getCliParamBool(const std::string /* id */) const = 0; + virtual real_type getCliParamReal(const std::string /* id */) const = 0.0; + virtual bool getCliParamBool(const std::string /* id */) const = false; virtual int printCliParam(const std::string /* id */) const = 0; protected: diff --git a/resolve/LinSolverDirectCuSolverRf.hpp b/resolve/LinSolverDirectCuSolverRf.hpp index 70f2d527..aa8ad594 100644 --- a/resolve/LinSolverDirectCuSolverRf.hpp +++ b/resolve/LinSolverDirectCuSolverRf.hpp @@ -43,7 +43,7 @@ namespace ReSolve int solve(vector_type* rhs) override; // rhs overwritten by solution void setAlgorithms(cusolverRfFactorization_t fact_alg, - cusolverRfTriangularSolve_t solve_alg); + cusolverRfTriangularSolve_t solve_alg); int setNumericalProperties(real_type nzero, real_type nboost); int setCliParam(const std::string id, const std::string value) override; From 3c49aeb56ef897909d5b39280da002cf46b2a3f7 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Thu, 23 Jan 2025 21:46:47 +0000 Subject: [PATCH 09/13] fixed minor typos --- resolve/LinSolverDirectCuSolverGLU.cpp | 2 +- resolve/LinSolverDirectCuSolverGLU.hpp | 4 ++-- resolve/LinSolverDirectRocSolverRf.hpp | 2 +- resolve/cusolver_defs.hpp | 4 ++-- resolve/matrix/MatrixHandlerCuda.cpp | 2 +- resolve/vector/VectorHandlerCuda.cpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/resolve/LinSolverDirectCuSolverGLU.cpp b/resolve/LinSolverDirectCuSolverGLU.cpp index bfa182a6..65051685 100644 --- a/resolve/LinSolverDirectCuSolverGLU.cpp +++ b/resolve/LinSolverDirectCuSolverGLU.cpp @@ -187,7 +187,7 @@ namespace ReSolve rhs->getData(memory::DEVICE),/* right hand side */ x->getData(memory::DEVICE), /* left hand side */ &ite_refine_succ_, - &r_nrminf_, + &r_nrm_inf_, info_M_, glu_buffer_); return status_cusolver_; diff --git a/resolve/LinSolverDirectCuSolverGLU.hpp b/resolve/LinSolverDirectCuSolverGLU.hpp index a4c11823..4e44c708 100644 --- a/resolve/LinSolverDirectCuSolverGLU.hpp +++ b/resolve/LinSolverDirectCuSolverGLU.hpp @@ -50,7 +50,7 @@ namespace ReSolve int printCliParam(const std::string id) const override; private: - void addFactors(matrix::Sparse* L, matrix::Sparse* U); ///< creates L+U from sepeate L, U factors + void addFactors(matrix::Sparse* L, matrix::Sparse* U); ///< creates L+U from separate L, U factors matrix::Sparse* M_; ///< the matrix that contains added factors //note: we need cuSolver handle, we can copy it from the workspace to avoid double allocation cusparseMatDescr_t descr_M_; //this is NOT sparse matrix descriptor @@ -61,7 +61,7 @@ namespace ReSolve cusparseStatus_t status_cusparse_; csrgluInfo_t info_M_; void* glu_buffer_; - double r_nrminf_; ///< Error norm of the solution + double r_nrm_inf_; ///< Error norm of the solution int ite_refine_succ_; ///< Stores return value of cusolverSpDgluSolve MemoryHandler mem_; ///< Device memory manager object diff --git a/resolve/LinSolverDirectRocSolverRf.hpp b/resolve/LinSolverDirectRocSolverRf.hpp index 49340017..e5065fc9 100644 --- a/resolve/LinSolverDirectRocSolverRf.hpp +++ b/resolve/LinSolverDirectRocSolverRf.hpp @@ -60,7 +60,7 @@ namespace ReSolve private: // to be exported to matrix handler in a later time - void addFactors(matrix::Sparse* L, matrix::Sparse* U); //create L+U from sepeate L, U factors + void addFactors(matrix::Sparse* L, matrix::Sparse* U); //create L+U from separate L, U factors void initParamList(); rocblas_status status_rocblas_; diff --git a/resolve/cusolver_defs.hpp b/resolve/cusolver_defs.hpp index 1bab52da..bb1930cd 100644 --- a/resolve/cusolver_defs.hpp +++ b/resolve/cusolver_defs.hpp @@ -88,12 +88,12 @@ extern "C" { const double* d_b0, /* right hand side */ double* d_x, /* left hand side */ int* ite_refine_succ, - double* r_nrminf_ptr, + double* r_nrm_inf_ptr, csrgluInfo_t info, void* workspace); cusolverStatus_t CUSOLVERAPI - cusolverSpDnrminf(cusolverSpHandle_t handle, + cusolverSpDnrm_inf(cusolverSpHandle_t handle, int n, const double *x, double* result, /* |x|_inf, host */ diff --git a/resolve/matrix/MatrixHandlerCuda.cpp b/resolve/matrix/MatrixHandlerCuda.cpp index 837ea20e..a8f727cb 100644 --- a/resolve/matrix/MatrixHandlerCuda.cpp +++ b/resolve/matrix/MatrixHandlerCuda.cpp @@ -173,7 +173,7 @@ namespace ReSolve { A->getValues(memory::DEVICE), d_r); - int status = cusolverSpDnrminf(workspace_->getCusolverSpHandle(), + int status = cusolverSpDnrm_inf(workspace_->getCusolverSpHandle(), A->getNumRows(), d_r, norm, diff --git a/resolve/vector/VectorHandlerCuda.cpp b/resolve/vector/VectorHandlerCuda.cpp index 9519793f..0552ce08 100644 --- a/resolve/vector/VectorHandlerCuda.cpp +++ b/resolve/vector/VectorHandlerCuda.cpp @@ -91,13 +91,13 @@ namespace ReSolve { } real_type norm; // TODO: Shouldn't the return type be cusolverStatus_t ? - int status = cusolverSpDnrminf(workspace_->getCusolverSpHandle(), + int status = cusolverSpDnrm_inf(workspace_->getCusolverSpHandle(), x->getSize(), x->getData(memory::DEVICE), &norm, workspace_->getNormBuffer() /* at least 8192 bytes */); if (status) { - out::error() << "cusolverSpDnrminf failed with error code " << status << "\n"; + out::error() << "cusolverSpDnrm_inf failed with error code " << status << "\n"; } return norm; } From 5da9f17efa917c5bb907581da7e17cfecbbc8061 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Thu, 23 Jan 2025 21:55:33 +0000 Subject: [PATCH 10/13] fixed overzealous search and replace for norminf --- resolve/cusolver_defs.hpp | 2 +- resolve/matrix/MatrixHandlerCuda.cpp | 2 +- resolve/vector/VectorHandlerCuda.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resolve/cusolver_defs.hpp b/resolve/cusolver_defs.hpp index bb1930cd..c9db034c 100644 --- a/resolve/cusolver_defs.hpp +++ b/resolve/cusolver_defs.hpp @@ -93,7 +93,7 @@ extern "C" { void* workspace); cusolverStatus_t CUSOLVERAPI - cusolverSpDnrm_inf(cusolverSpHandle_t handle, + cusolverSpDnrminf(cusolverSpHandle_t handle, int n, const double *x, double* result, /* |x|_inf, host */ diff --git a/resolve/matrix/MatrixHandlerCuda.cpp b/resolve/matrix/MatrixHandlerCuda.cpp index a8f727cb..837ea20e 100644 --- a/resolve/matrix/MatrixHandlerCuda.cpp +++ b/resolve/matrix/MatrixHandlerCuda.cpp @@ -173,7 +173,7 @@ namespace ReSolve { A->getValues(memory::DEVICE), d_r); - int status = cusolverSpDnrm_inf(workspace_->getCusolverSpHandle(), + int status = cusolverSpDnrminf(workspace_->getCusolverSpHandle(), A->getNumRows(), d_r, norm, diff --git a/resolve/vector/VectorHandlerCuda.cpp b/resolve/vector/VectorHandlerCuda.cpp index 0552ce08..9519793f 100644 --- a/resolve/vector/VectorHandlerCuda.cpp +++ b/resolve/vector/VectorHandlerCuda.cpp @@ -91,13 +91,13 @@ namespace ReSolve { } real_type norm; // TODO: Shouldn't the return type be cusolverStatus_t ? - int status = cusolverSpDnrm_inf(workspace_->getCusolverSpHandle(), + int status = cusolverSpDnrminf(workspace_->getCusolverSpHandle(), x->getSize(), x->getData(memory::DEVICE), &norm, workspace_->getNormBuffer() /* at least 8192 bytes */); if (status) { - out::error() << "cusolverSpDnrm_inf failed with error code " << status << "\n"; + out::error() << "cusolverSpDnrminf failed with error code " << status << "\n"; } return norm; } From a71dca2815e4890610f8afb643e402f355ec7d8c Mon Sep 17 00:00:00 2001 From: shakedregev Date: Thu, 23 Jan 2025 22:09:12 +0000 Subject: [PATCH 11/13] tests pass --- resolve/LinSolver.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resolve/LinSolver.hpp b/resolve/LinSolver.hpp index ae35ca70..effec0ff 100644 --- a/resolve/LinSolver.hpp +++ b/resolve/LinSolver.hpp @@ -49,10 +49,10 @@ namespace ReSolve real_type evaluateResidual(); virtual int setCliParam(const std::string /* id */, const std::string /* value */) = 0; - virtual std::string getCliParamString(const std::string /* id */) const = ""; + virtual std::string getCliParamString(const std::string /* id */) const = 0; virtual index_type getCliParamInt(const std::string /* id */) const = 0; - virtual real_type getCliParamReal(const std::string /* id */) const = 0.0; - virtual bool getCliParamBool(const std::string /* id */) const = false; + virtual real_type getCliParamReal(const std::string /* id */) const = 0; + virtual bool getCliParamBool(const std::string /* id */) const = 0; virtual int printCliParam(const std::string /* id */) const = 0; protected: From c9a91684cda3e088376e062b49ae1449d2612932 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Thu, 23 Jan 2025 20:08:58 -0500 Subject: [PATCH 12/13] Fix doxygen --- resolve/LinSolver.cpp | 2 +- resolve/LinSolver.hpp | 2 +- resolve/LinSolverDirect.cpp | 2 +- resolve/LinSolverDirect.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resolve/LinSolver.cpp b/resolve/LinSolver.cpp index 8536d9e1..75bc15b6 100644 --- a/resolve/LinSolver.cpp +++ b/resolve/LinSolver.cpp @@ -1,5 +1,5 @@ /** - * @file LinSolverIterative.cpp + * @file LinSolver.cpp * @author Kasia Swirydowicz (kasia.swirydowicz@pnnl.gov) * @author Slaven Peles (peless@ornl.gov) * @brief Implementation of linear solver base class. diff --git a/resolve/LinSolver.hpp b/resolve/LinSolver.hpp index effec0ff..556b1412 100644 --- a/resolve/LinSolver.hpp +++ b/resolve/LinSolver.hpp @@ -1,5 +1,5 @@ /** - * @file LinSolverIterative.hpp + * @file LinSolver.hpp * @author Kasia Swirydowicz (kasia.swirydowicz@pnnl.gov) * @author Slaven Peles (peless@ornl.gov) * @brief Declaration of linear solver base class. diff --git a/resolve/LinSolverDirect.cpp b/resolve/LinSolverDirect.cpp index 3737cf60..689b8cbf 100644 --- a/resolve/LinSolverDirect.cpp +++ b/resolve/LinSolverDirect.cpp @@ -1,5 +1,5 @@ /** - * @file LinSolverIterative.cpp + * @file LinSolverDirect.cpp * @author Kasia Swirydowicz (kasia.swirydowicz@pnnl.gov) * @author Slaven Peles (peless@ornl.gov) * @brief Implementation of direct solver base class. diff --git a/resolve/LinSolverDirect.hpp b/resolve/LinSolverDirect.hpp index e5aea729..7623f074 100644 --- a/resolve/LinSolverDirect.hpp +++ b/resolve/LinSolverDirect.hpp @@ -1,5 +1,5 @@ /** - * @file LinSolverIterative.hpp + * @file LinSolverDirect.hpp * @author Kasia Swirydowicz (kasia.swirydowicz@pnnl.gov) * @author Slaven Peles (peless@ornl.gov) * @brief Declaration of direct solver base class. From cc0c371599c5d54ce9a6923b8d22fbe8052f8d89 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Fri, 24 Jan 2025 11:17:24 -0500 Subject: [PATCH 13/13] Document placeholder parameter set/get methods. --- resolve/LinSolverDirectCpuILU0.cpp | 50 ++++++++++++++++++++++++ resolve/LinSolverDirectCuSolverGLU.cpp | 50 ++++++++++++++++++++++++ resolve/LinSolverDirectCuSolverRf.cpp | 30 ++++++++++++++ resolve/LinSolverDirectCuSparseILU0.cpp | 50 ++++++++++++++++++++++++ resolve/LinSolverDirectKLU.cpp | 20 ++++++++++ resolve/LinSolverDirectLUSOL.cpp | 50 ++++++++++++++++++++++++ resolve/LinSolverDirectRocSolverRf.cpp | 40 +++++++++++++++++++ resolve/LinSolverDirectRocSparseILU0.cpp | 50 ++++++++++++++++++++++++ resolve/LinSolverDirectSerialILU0.cpp | 50 ++++++++++++++++++++++++ 9 files changed, 390 insertions(+) diff --git a/resolve/LinSolverDirectCpuILU0.cpp b/resolve/LinSolverDirectCpuILU0.cpp index 0b470c4e..92f6b289 100644 --- a/resolve/LinSolverDirectCpuILU0.cpp +++ b/resolve/LinSolverDirectCpuILU0.cpp @@ -347,6 +347,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to set. + * @return int Error code. + */ int LinSolverDirectCpuILU0::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) @@ -357,6 +367,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return std::string Value of the string parameter to return. + */ std::string LinSolverDirectCpuILU0::getCliParamString(const std::string id) const { switch (getParamId(id)) @@ -367,6 +387,16 @@ namespace ReSolve return ""; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return int Value of the int parameter to return. + */ index_type LinSolverDirectCpuILU0::getCliParamInt(const std::string id) const { switch (getParamId(id)) @@ -377,6 +407,16 @@ namespace ReSolve return -1; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return real_type Value of the real_type parameter to return. + */ real_type LinSolverDirectCpuILU0::getCliParamReal(const std::string id) const { switch (getParamId(id)) @@ -387,6 +427,16 @@ namespace ReSolve return std::numeric_limits::quiet_NaN(); } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return bool Value of the bool parameter to return. + */ bool LinSolverDirectCpuILU0::getCliParamBool(const std::string id) const { switch (getParamId(id)) diff --git a/resolve/LinSolverDirectCuSolverGLU.cpp b/resolve/LinSolverDirectCuSolverGLU.cpp index 65051685..85c5203b 100644 --- a/resolve/LinSolverDirectCuSolverGLU.cpp +++ b/resolve/LinSolverDirectCuSolverGLU.cpp @@ -200,6 +200,16 @@ namespace ReSolve return 1; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to set. + * @return int Error code. + */ int LinSolverDirectCuSolverGLU::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) @@ -210,6 +220,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return std::string Value of the string parameter to return. + */ std::string LinSolverDirectCuSolverGLU::getCliParamString(const std::string id) const { switch (getParamId(id)) @@ -220,6 +240,16 @@ namespace ReSolve return ""; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return int Value of the int parameter to return. + */ index_type LinSolverDirectCuSolverGLU::getCliParamInt(const std::string id) const { switch (getParamId(id)) @@ -230,6 +260,16 @@ namespace ReSolve return -1; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return real_type Value of the real_type parameter to return. + */ real_type LinSolverDirectCuSolverGLU::getCliParamReal(const std::string id) const { switch (getParamId(id)) @@ -240,6 +280,16 @@ namespace ReSolve return std::numeric_limits::quiet_NaN(); } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return bool Value of the bool parameter to return. + */ bool LinSolverDirectCuSolverGLU::getCliParamBool(const std::string id) const { switch (getParamId(id)) diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index 27ae4712..67f01919 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -180,6 +180,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return std::string Value of the string parameter to return. + */ std::string LinSolverDirectCuSolverRf::getCliParamString(const std::string id) const { switch (getParamId(id)) @@ -190,6 +200,16 @@ namespace ReSolve return ""; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return int Value of the int parameter to return. + */ index_type LinSolverDirectCuSolverRf::getCliParamInt(const std::string id) const { switch (getParamId(id)) @@ -214,6 +234,16 @@ namespace ReSolve return std::numeric_limits::quiet_NaN(); } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return bool Value of the bool parameter to return. + */ bool LinSolverDirectCuSolverRf::getCliParamBool(const std::string id) const { switch (getParamId(id)) diff --git a/resolve/LinSolverDirectCuSparseILU0.cpp b/resolve/LinSolverDirectCuSparseILU0.cpp index a583d031..c94945ad 100644 --- a/resolve/LinSolverDirectCuSparseILU0.cpp +++ b/resolve/LinSolverDirectCuSparseILU0.cpp @@ -313,6 +313,16 @@ namespace ReSolve return error_sum; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to set. + * @return int Error code. + */ int LinSolverDirectCuSparseILU0::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) @@ -323,6 +333,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return std::string Value of the string parameter to return. + */ std::string LinSolverDirectCuSparseILU0::getCliParamString(const std::string id) const { switch (getParamId(id)) @@ -333,6 +353,16 @@ namespace ReSolve return ""; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return int Value of the int parameter to return. + */ index_type LinSolverDirectCuSparseILU0::getCliParamInt(const std::string id) const { switch (getParamId(id)) @@ -343,6 +373,16 @@ namespace ReSolve return -1; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return real_type Value of the real_type parameter to return. + */ real_type LinSolverDirectCuSparseILU0::getCliParamReal(const std::string id) const { switch (getParamId(id)) @@ -353,6 +393,16 @@ namespace ReSolve return std::numeric_limits::quiet_NaN(); } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return bool Value of the bool parameter to return. + */ bool LinSolverDirectCuSparseILU0::getCliParamBool(const std::string id) const { switch (getParamId(id)) diff --git a/resolve/LinSolverDirectKLU.cpp b/resolve/LinSolverDirectKLU.cpp index 11191e03..da7b08c2 100644 --- a/resolve/LinSolverDirectKLU.cpp +++ b/resolve/LinSolverDirectKLU.cpp @@ -311,6 +311,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return std::string Value of the string parameter to return. + */ std::string LinSolverDirectKLU::getCliParamString(const std::string id) const { switch (getParamId(id)) @@ -333,6 +343,16 @@ namespace ReSolve return -1; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return real_type Value of the real_type parameter to return. + */ real_type LinSolverDirectKLU::getCliParamReal(const std::string id) const { switch (getParamId(id)) diff --git a/resolve/LinSolverDirectLUSOL.cpp b/resolve/LinSolverDirectLUSOL.cpp index 9fb6741c..039beff7 100644 --- a/resolve/LinSolverDirectLUSOL.cpp +++ b/resolve/LinSolverDirectLUSOL.cpp @@ -448,6 +448,16 @@ namespace ReSolve return Q_; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to set. + * @return int Error code. + */ int LinSolverDirectLUSOL::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) @@ -458,6 +468,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return std::string Value of the string parameter to return. + */ std::string LinSolverDirectLUSOL::getCliParamString(const std::string id) const { switch (getParamId(id)) @@ -468,6 +488,16 @@ namespace ReSolve return ""; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return int Value of the int parameter to return. + */ index_type LinSolverDirectLUSOL::getCliParamInt(const std::string id) const { switch (getParamId(id)) @@ -478,6 +508,16 @@ namespace ReSolve return -1; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return real_type Value of the real_type parameter to return. + */ real_type LinSolverDirectLUSOL::getCliParamReal(const std::string id) const { switch (getParamId(id)) @@ -488,6 +528,16 @@ namespace ReSolve return std::numeric_limits::quiet_NaN(); } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return bool Value of the bool parameter to return. + */ bool LinSolverDirectLUSOL::getCliParamBool(const std::string id) const { switch (getParamId(id)) diff --git a/resolve/LinSolverDirectRocSolverRf.cpp b/resolve/LinSolverDirectRocSolverRf.cpp index b63938e1..f39714ea 100644 --- a/resolve/LinSolverDirectRocSolverRf.cpp +++ b/resolve/LinSolverDirectRocSolverRf.cpp @@ -404,6 +404,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return std::string Value of the string parameter to return. + */ std::string LinSolverDirectRocSolverRf::getCliParamString(const std::string id) const { std::string value(""); @@ -425,6 +435,16 @@ namespace ReSolve return value; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return int Value of the int parameter to return. + */ index_type LinSolverDirectRocSolverRf::getCliParamInt(const std::string id) const { switch (getParamId(id)) @@ -435,6 +455,16 @@ namespace ReSolve return -1; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return real_type Value of the real_type parameter to return. + */ real_type LinSolverDirectRocSolverRf::getCliParamReal(const std::string id) const { switch (getParamId(id)) @@ -445,6 +475,16 @@ namespace ReSolve return std::numeric_limits::quiet_NaN(); } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return bool Value of the bool parameter to return. + */ bool LinSolverDirectRocSolverRf::getCliParamBool(const std::string id) const { switch (getParamId(id)) diff --git a/resolve/LinSolverDirectRocSparseILU0.cpp b/resolve/LinSolverDirectRocSparseILU0.cpp index 669daa63..4dc65dfc 100644 --- a/resolve/LinSolverDirectRocSparseILU0.cpp +++ b/resolve/LinSolverDirectRocSparseILU0.cpp @@ -293,6 +293,16 @@ namespace ReSolve return error_sum; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return int Value of the int parameter to return. + */ int LinSolverDirectRocSparseILU0::setCliParam(const std::string id, const std::string value) { switch (getParamId(id)) @@ -303,6 +313,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return std::string Value of the string parameter to return. + */ std::string LinSolverDirectRocSparseILU0::getCliParamString(const std::string id) const { switch (getParamId(id)) @@ -313,6 +333,16 @@ namespace ReSolve return ""; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return int Value of the int parameter to return. + */ index_type LinSolverDirectRocSparseILU0::getCliParamInt(const std::string id) const { switch (getParamId(id)) @@ -323,6 +353,16 @@ namespace ReSolve return -1; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return real_type Value of the real_type parameter to return. + */ real_type LinSolverDirectRocSparseILU0::getCliParamReal(const std::string id) const { switch (getParamId(id)) @@ -333,6 +373,16 @@ namespace ReSolve return std::numeric_limits::quiet_NaN(); } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return bool Value of the bool parameter to return. + */ bool LinSolverDirectRocSparseILU0::getCliParamBool(const std::string id) const { switch (getParamId(id)) diff --git a/resolve/LinSolverDirectSerialILU0.cpp b/resolve/LinSolverDirectSerialILU0.cpp index 6082ceca..930bbae2 100644 --- a/resolve/LinSolverDirectSerialILU0.cpp +++ b/resolve/LinSolverDirectSerialILU0.cpp @@ -239,6 +239,16 @@ namespace ReSolve return error_sum; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to set. + * @return int Error code. + */ int LinSolverDirectSerialILU0::setCliParam(const std::string id, const std::string /* value */) { switch (getParamId(id)) @@ -249,6 +259,16 @@ namespace ReSolve return 0; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return std::string Value of the string parameter to return. + */ std::string LinSolverDirectSerialILU0::getCliParamString(const std::string id) const { switch (getParamId(id)) @@ -259,6 +279,16 @@ namespace ReSolve return ""; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return int Value of the int parameter to return. + */ index_type LinSolverDirectSerialILU0::getCliParamInt(const std::string id) const { switch (getParamId(id)) @@ -269,6 +299,16 @@ namespace ReSolve return -1; } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return real_type Value of the real_type parameter to return. + */ real_type LinSolverDirectSerialILU0::getCliParamReal(const std::string id) const { switch (getParamId(id)) @@ -279,6 +319,16 @@ namespace ReSolve return std::numeric_limits::quiet_NaN(); } + /** + * @brief Placeholder function for now. + * + * The following switch (getParamId(Id)) cases always run the default and + * are currently redundant code (like an if (true)). + * In the future, they will be expanded to include more options. + * + * @param id - string ID for parameter to get. + * @return bool Value of the bool parameter to return. + */ bool LinSolverDirectSerialILU0::getCliParamBool(const std::string id) const { switch (getParamId(id))