From 108219c26a2d567de277130f4737a82ba96f47bc Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 7 Oct 2025 09:18:38 -0400 Subject: [PATCH 01/14] started handling errors properly --- examples/ExampleHelper.hpp | 6 +----- resolve/LinSolverDirect.cpp | 1 + resolve/LinSolverDirectCuSolverRf.cpp | 28 ++++++++++++++------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/examples/ExampleHelper.hpp b/examples/ExampleHelper.hpp index ec812c263..b3c1590bb 100644 --- a/examples/ExampleHelper.hpp +++ b/examples/ExampleHelper.hpp @@ -142,14 +142,10 @@ namespace ReSolve ReSolve::vector::Vector* r, ReSolve::vector::Vector* x) { + assert(res_ != nullptr && "resetSystem should be called after setSystem"); A_ = A; r_ = r; x_ = x; - if (res_ == nullptr) - { - res_ = new ReSolve::vector::Vector(A->getNumRows()); - } - computeNorms(); } diff --git a/resolve/LinSolverDirect.cpp b/resolve/LinSolverDirect.cpp index d82e1046c..1f41cdb19 100644 --- a/resolve/LinSolverDirect.cpp +++ b/resolve/LinSolverDirect.cpp @@ -55,6 +55,7 @@ namespace ReSolve { if (A == nullptr) { + out::error() << "LinSolverDirect::setup: input matrix A is nullptr" << std::endl; return 1; } A_ = A; diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index d4f94429d..55b12e585 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -50,6 +50,7 @@ namespace ReSolve * * Sets up the cuSolverRf factorization for the given matrix A and its * L and U factors. The permutation vectors P and Q are also set up. + * This function should not be called more than once for the same object. * * @param[in] A - pointer to the matrix A * @param[in] L - pointer to the lower triangular factor L in CSR @@ -75,31 +76,32 @@ namespace ReSolve this->A_ = A; index_type n = A_->getNumRows(); - // Remember - P and Q are generally CPU variables! - // Factorization data is stored in the handle. - // If function is called again, destroy the old handle to get rid of old data. - if (setup_completed_) - { - cusolverRfDestroy(handle_cusolverrf_); - cusolverRfCreate(&handle_cusolverrf_); - } - if (d_P_ == nullptr) { mem_.allocateArrayOnDevice(&d_P_, n); } + else + { + out::error() << "d_P_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" std::endl; + } if (d_Q_ == nullptr) { mem_.allocateArrayOnDevice(&d_Q_, n); } - - if (d_T_ != nullptr) + else { - mem_.deleteOnDevice(d_T_); + out::error() << "d_Q_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" std::endl; } - mem_.allocateArrayOnDevice(&d_T_, n); + if (d_T_ == nullptr) + { + mem_.allocateArrayOnDevice(&d_T_, n); + } + else + { + out::error() << "d_T_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" std::endl; + } mem_.copyArrayHostToDevice(d_P_, P, n); mem_.copyArrayHostToDevice(d_Q_, Q, n); From 16d2a56d3bb247bdec1f7e371ca6ec2055661443 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 7 Oct 2025 09:30:13 -0400 Subject: [PATCH 02/14] corrected error logs --- resolve/LinSolverDirectKLU.cpp | 4 +++- resolve/LinSolverDirectRocSolverRf.cpp | 8 ++++++++ resolve/LinSolverIterative.cpp | 1 + resolve/MemoryUtils.hpp | 14 +++++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/resolve/LinSolverDirectKLU.cpp b/resolve/LinSolverDirectKLU.cpp index ecde2f48f..8a1f2ee93 100644 --- a/resolve/LinSolverDirectKLU.cpp +++ b/resolve/LinSolverDirectKLU.cpp @@ -127,7 +127,7 @@ namespace ReSolve if (Symbolic_ == nullptr) { out::error() << "Symbolic_ factorization failed with Common_.status = " - << Common_.status << "\n"; + << Common_.status << std::endl; return 1; } return 0; @@ -167,6 +167,8 @@ namespace ReSolve if (Numeric_ == nullptr) { + out::error() << "Numeric_ factorization failed with Common_.status = " + << Common_.status << std::endl; return 1; } else diff --git a/resolve/LinSolverDirectRocSolverRf.cpp b/resolve/LinSolverDirectRocSolverRf.cpp index 4f0ebc50e..f37a743e3 100644 --- a/resolve/LinSolverDirectRocSolverRf.cpp +++ b/resolve/LinSolverDirectRocSolverRf.cpp @@ -82,11 +82,19 @@ namespace ReSolve { mem_.allocateArrayOnDevice(&d_P_, n); } + else + { + out::error() << "d_P_ should be nullptr on call to LinSolverDirectRocSolverRf::setup" << std::endl; + } if (d_Q_ == nullptr) { mem_.allocateArrayOnDevice(&d_Q_, n); } + else + { + out::error() << "d_Q_ should be nullptr on call to LinSolverDirectRocSolverRf::setup" << std::endl; + } mem_.copyArrayHostToDevice(d_P_, P, n); mem_.copyArrayHostToDevice(d_Q_, Q, n); diff --git a/resolve/LinSolverIterative.cpp b/resolve/LinSolverIterative.cpp index c24af8f76..d94c5919b 100644 --- a/resolve/LinSolverIterative.cpp +++ b/resolve/LinSolverIterative.cpp @@ -26,6 +26,7 @@ namespace ReSolve { if (A == nullptr) { + out::error() << "LinSolverIterative::setup: input matrix A is nullptr" << std::endl; return 1; } this->A_ = A; diff --git a/resolve/MemoryUtils.hpp b/resolve/MemoryUtils.hpp index 702d80ea6..a22196074 100644 --- a/resolve/MemoryUtils.hpp +++ b/resolve/MemoryUtils.hpp @@ -1,11 +1,13 @@ #pragma once #include // <- declares `memcpy` +#include #include namespace ReSolve { + using out = ReSolve::io::Logger; namespace memory { enum MemorySpace @@ -86,12 +88,22 @@ namespace ReSolve { std::size_t arraysize = static_cast(n) * sizeof(T); *v = new T[arraysize]; - return *v == nullptr ? 1 : 0; + if (*v== nullptr) + { + out::error() << "Memory allocation on host failed for size " << arraysize << " bytes." << std::endl; + return 1; + } + return 0; } template int deleteOnHost(T* v) { + if (v== nullptr) + { + out::error() << "Trying to delete nullptr on host!" << std::endl; + return 1; + } delete[] v; v = nullptr; return 0; From aa7ffb7411b0a9b5fbeda2be65bca9a3c4c88503 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 7 Oct 2025 10:00:28 -0400 Subject: [PATCH 03/14] removed sloppy function calling --- resolve/SystemSolver.cpp | 19 +++++++++++++------ resolve/matrix/io.cpp | 11 +++++------ resolve/vector/Vector.cpp | 8 ++++---- tests/unit/matrix/MatrixHandlerTests.hpp | 6 ++++++ 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/resolve/SystemSolver.cpp b/resolve/SystemSolver.cpp index 884c3fbd2..0abd0423a 100644 --- a/resolve/SystemSolver.cpp +++ b/resolve/SystemSolver.cpp @@ -372,10 +372,6 @@ namespace ReSolve vectorHandler_, gs_); } - else - { - // do nothing - } return 0; } @@ -393,32 +389,43 @@ namespace ReSolve factorizationSolver_->setup(A_); return factorizationSolver_->analyze(); } + out::error() << "Analyze method not set to a valid method!" << std::endl; return 1; } int SystemSolver::factorize() { + if (A_ == nullptr) + { + out::error() << "System matrix not set!\n"; + return 1; + } if (factorizationMethod_ == "klu") { is_solve_on_device_ = false; return factorizationSolver_->factorize(); } + out::error() << "Factorization method not set to a valid method!" << std::endl; return 1; } int SystemSolver::refactorize() { + if (A_ == nullptr) + { + out::error() << "System matrix not set!\n"; + return 1; + } if (refactorizationMethod_ == "klu") { return factorizationSolver_->refactorize(); } - if (refactorizationMethod_ == "glu" || refactorizationMethod_ == "cusolverrf" || refactorizationMethod_ == "rocsolverrf") { is_solve_on_device_ = true; return refactorizationSolver_->refactorize(); } - + out::error() << "Refactorization method not set to a valid method!" << std::endl; return 1; } diff --git a/resolve/matrix/io.cpp b/resolve/matrix/io.cpp index ae8502ae8..ffcdf5cfc 100644 --- a/resolve/matrix/io.cpp +++ b/resolve/matrix/io.cpp @@ -386,7 +386,11 @@ namespace ReSolve Logger::error() << "Empty input to updateArrayFromFile function ..." << std::endl; return; } - + if (p_rhs == nullptr) + { + Logger::error() << "Null pointer to array in updateArrayFromFile function ..." << std::endl; + return; + } real_type* rhs = *p_rhs; std::stringstream ss; std::string line; @@ -399,11 +403,6 @@ namespace ReSolve } ss << line; ss >> n >> m; - - if (rhs == nullptr) - { - rhs = new real_type[n]; - } real_type a; index_type i = 0; while (file >> a) diff --git a/resolve/vector/Vector.cpp b/resolve/vector/Vector.cpp index 6d61d08ec..a4203fabe 100644 --- a/resolve/vector/Vector.cpp +++ b/resolve/vector/Vector.cpp @@ -681,8 +681,8 @@ namespace ReSolve case HOST: if (h_data_ == nullptr) { - h_data_ = new real_type[n_capacity_ * k_]; - owns_cpu_data_ = true; + out::error() << "Trying to set vector host values, but the values are not allocated!" << std::endl; + return 1; } mem_.setArrayToConstOnHost(&h_data_[n_size_ * j], C, n_size_); cpu_updated_[j] = true; @@ -691,8 +691,8 @@ namespace ReSolve case DEVICE: if (d_data_ == nullptr) { - mem_.allocateArrayOnDevice(&d_data_, n_capacity_ * k_); - owns_gpu_data_ = true; + out::error() << "Trying to set vector device values, but the values are not allocated!" << std::endl; + return 1; } mem_.setArrayToConstOnDevice(&d_data_[n_size_ * j], C, n_size_); cpu_updated_[j] = false; diff --git a/tests/unit/matrix/MatrixHandlerTests.hpp b/tests/unit/matrix/MatrixHandlerTests.hpp index e6fb0eac9..2a26043c8 100644 --- a/tests/unit/matrix/MatrixHandlerTests.hpp +++ b/tests/unit/matrix/MatrixHandlerTests.hpp @@ -10,10 +10,13 @@ #include #include #include +#include #include + namespace ReSolve { + using out = io::Logger; namespace tests { @@ -616,6 +619,7 @@ namespace ReSolve // Check if the matrix is valid if (A == nullptr) { + out::error() << "Matrix pointer is NULL in " << __func__ << std::endl; return false; } @@ -697,6 +701,7 @@ namespace ReSolve // Check if the matrix is valid if (A == nullptr) { + out::error() << "Matrix pointer is NULL in " << __func__ << std::endl; return false; } @@ -780,6 +785,7 @@ namespace ReSolve // Check if the vector is valid if (scaled_vec == nullptr) { + out::error() << "Vector pointer is NULL in " << __func__ << std::endl; return false; } From ed01dd46367733c19fde62ac84776f61971a9f11 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 7 Oct 2025 10:08:04 -0400 Subject: [PATCH 04/14] removed sloppy function calls --- resolve/vector/Vector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolve/vector/Vector.cpp b/resolve/vector/Vector.cpp index a4203fabe..a291926a0 100644 --- a/resolve/vector/Vector.cpp +++ b/resolve/vector/Vector.cpp @@ -632,7 +632,7 @@ namespace ReSolve * In case of multivectors, entire multivector is set to the constant. * * @param[in] C - Constant (real number) - * @param[in] memspace - Memory space of the data to be set to 0 (HOST or DEVICE) + * @param[in] memspace - Memory space of the data to be set to constant (HOST or DEVICE) * */ int Vector::setToConst(real_type C, memory::MemorySpace memspace) From b4575fb9be9cda6900fba9567799e97849b3da98 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 7 Oct 2025 10:14:33 -0400 Subject: [PATCH 05/14] renamed constant --- resolve/vector/Vector.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resolve/vector/Vector.cpp b/resolve/vector/Vector.cpp index a291926a0..565b007ae 100644 --- a/resolve/vector/Vector.cpp +++ b/resolve/vector/Vector.cpp @@ -631,11 +631,11 @@ namespace ReSolve * * In case of multivectors, entire multivector is set to the constant. * - * @param[in] C - Constant (real number) + * @param[in] constant - Constant (real number) * @param[in] memspace - Memory space of the data to be set to constant (HOST or DEVICE) * */ - int Vector::setToConst(real_type C, memory::MemorySpace memspace) + int Vector::setToConst(real_type constant, memory::MemorySpace memspace) { using namespace ReSolve::memory; switch (memspace) @@ -646,7 +646,7 @@ namespace ReSolve h_data_ = new real_type[n_capacity_ * k_]; owns_cpu_data_ = true; } - mem_.setArrayToConstOnHost(h_data_, C, n_size_ * k_); + mem_.setArrayToConstOnHost(h_data_, constant, n_size_ * k_); setHostUpdated(true); setDeviceUpdated(false); break; @@ -656,7 +656,7 @@ namespace ReSolve mem_.allocateArrayOnDevice(&d_data_, n_capacity_ * k_); owns_gpu_data_ = true; } - mem_.setArrayToConstOnDevice(d_data_, C, n_size_ * k_); + mem_.setArrayToConstOnDevice(d_data_, constant, n_size_ * k_); setHostUpdated(false); setDeviceUpdated(true); break; From 97cbf1b919f717cca9d4c57a8b7a7442085f17f6 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 7 Oct 2025 10:16:21 -0400 Subject: [PATCH 06/14] constant name update --- resolve/vector/Vector.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resolve/vector/Vector.cpp b/resolve/vector/Vector.cpp index 565b007ae..e503c2f20 100644 --- a/resolve/vector/Vector.cpp +++ b/resolve/vector/Vector.cpp @@ -631,7 +631,7 @@ namespace ReSolve * * In case of multivectors, entire multivector is set to the constant. * - * @param[in] constant - Constant (real number) + * @param[in] constant - Constant (real number) * @param[in] memspace - Memory space of the data to be set to constant (HOST or DEVICE) * */ @@ -668,12 +668,12 @@ namespace ReSolve * @brief set the data of a single vector in a multivector to a given constant. * * @param[in] j - Index of a vector in a multivector - * @param[in] C - Constant (real number) + * @param[in] constant - Constant (real number) * @param[in] memspace - Memory space of the data to be set to 0 (HOST or DEVICE) * * @pre _j_ < _k_ i.e,, _j_ is smaller than the total number of vectors in multivector. */ - int Vector::setToConst(index_type j, real_type C, memory::MemorySpace memspace) + int Vector::setToConst(index_type j, real_type constant, memory::MemorySpace memspace) { using namespace ReSolve::memory; switch (memspace) @@ -684,7 +684,7 @@ namespace ReSolve out::error() << "Trying to set vector host values, but the values are not allocated!" << std::endl; return 1; } - mem_.setArrayToConstOnHost(&h_data_[n_size_ * j], C, n_size_); + mem_.setArrayToConstOnHost(&h_data_[n_size_ * j], constant, n_size_); cpu_updated_[j] = true; gpu_updated_[j] = false; break; @@ -694,7 +694,7 @@ namespace ReSolve out::error() << "Trying to set vector device values, but the values are not allocated!" << std::endl; return 1; } - mem_.setArrayToConstOnDevice(&d_data_[n_size_ * j], C, n_size_); + mem_.setArrayToConstOnDevice(&d_data_[n_size_ * j], constant, n_size_); cpu_updated_[j] = false; gpu_updated_[j] = true; break; From f1f54298ca952e5773868b2f0446667a1cabea07 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 7 Oct 2025 14:32:09 +0000 Subject: [PATCH 07/14] Apply pre-commmit fixes --- resolve/MemoryUtils.hpp | 9 +++++---- tests/unit/matrix/MatrixHandlerTests.hpp | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/resolve/MemoryUtils.hpp b/resolve/MemoryUtils.hpp index a22196074..04f2ad92c 100644 --- a/resolve/MemoryUtils.hpp +++ b/resolve/MemoryUtils.hpp @@ -1,13 +1,14 @@ #pragma once #include // <- declares `memcpy` -#include #include +#include namespace ReSolve { using out = ReSolve::io::Logger; + namespace memory { enum MemorySpace @@ -88,18 +89,18 @@ namespace ReSolve { std::size_t arraysize = static_cast(n) * sizeof(T); *v = new T[arraysize]; - if (*v== nullptr) + if (*v == nullptr) { out::error() << "Memory allocation on host failed for size " << arraysize << " bytes." << std::endl; return 1; } - return 0; + return 0; } template int deleteOnHost(T* v) { - if (v== nullptr) + if (v == nullptr) { out::error() << "Trying to delete nullptr on host!" << std::endl; return 1; diff --git a/tests/unit/matrix/MatrixHandlerTests.hpp b/tests/unit/matrix/MatrixHandlerTests.hpp index 2a26043c8..e624ad6e7 100644 --- a/tests/unit/matrix/MatrixHandlerTests.hpp +++ b/tests/unit/matrix/MatrixHandlerTests.hpp @@ -8,15 +8,15 @@ #include #include #include +#include #include #include -#include #include - namespace ReSolve { using out = io::Logger; + namespace tests { From 2ed1d43e0b089f83ccd28ae653cfdd8c87d52b13 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 7 Oct 2025 14:38:56 +0000 Subject: [PATCH 08/14] typo fix --- resolve/LinSolverDirectCuSolverRf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index 55b12e585..d29e47f51 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -82,7 +82,7 @@ namespace ReSolve } else { - out::error() << "d_P_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" std::endl; + out::error() << "d_P_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" << std::endl; } if (d_Q_ == nullptr) @@ -91,7 +91,7 @@ namespace ReSolve } else { - out::error() << "d_Q_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" std::endl; + out::error() << "d_Q_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" << std::endl; } if (d_T_ == nullptr) @@ -100,7 +100,7 @@ namespace ReSolve } else { - out::error() << "d_T_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" std::endl; + out::error() << "d_T_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" << std::endl; } mem_.copyArrayHostToDevice(d_P_, P, n); From e15519e838a4d33e9b07c19e11967be8967cb9b8 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Wed, 8 Oct 2025 11:31:58 -0400 Subject: [PATCH 09/14] added back check if setup is complete --- resolve/LinSolverDirectCuSolverRf.cpp | 9 +++++++-- resolve/LinSolverDirectRocSolverRf.cpp | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index d29e47f51..c343f8b91 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -76,13 +76,18 @@ namespace ReSolve this->A_ = A; index_type n = A_->getNumRows(); + if (setup_completed_) + { + out::error() << "LinSolverDirectCuSolverRf::setup should only be called one." << std::endl; + } + if (d_P_ == nullptr) { mem_.allocateArrayOnDevice(&d_P_, n); } else { - out::error() << "d_P_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" << std::endl; + out::error() << "d_P_ should be nullptr on call to LinSolverDirectCuSolverRf::setup." << std::endl; } if (d_Q_ == nullptr) @@ -91,7 +96,7 @@ namespace ReSolve } else { - out::error() << "d_Q_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" << std::endl; + out::error() << "d_Q_ should be nullptr on call to LinSolverDirectCuSolverRf::setup." << std::endl; } if (d_T_ == nullptr) diff --git a/resolve/LinSolverDirectRocSolverRf.cpp b/resolve/LinSolverDirectRocSolverRf.cpp index f37a743e3..eb03958c9 100644 --- a/resolve/LinSolverDirectRocSolverRf.cpp +++ b/resolve/LinSolverDirectRocSolverRf.cpp @@ -84,7 +84,7 @@ namespace ReSolve } else { - out::error() << "d_P_ should be nullptr on call to LinSolverDirectRocSolverRf::setup" << std::endl; + out::error() << "d_P_ should be nullptr on call to LinSolverDirectRocSolverRf::setup." << std::endl; } if (d_Q_ == nullptr) @@ -93,7 +93,7 @@ namespace ReSolve } else { - out::error() << "d_Q_ should be nullptr on call to LinSolverDirectRocSolverRf::setup" << std::endl; + out::error() << "d_Q_ should be nullptr on call to LinSolverDirectRocSolverRf::setup." << std::endl; } mem_.copyArrayHostToDevice(d_P_, P, n); mem_.copyArrayHostToDevice(d_Q_, Q, n); From 727af736a6d9d293bd129036355586d22806a436 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Wed, 8 Oct 2025 11:44:15 -0400 Subject: [PATCH 10/14] added return 1s --- resolve/LinSolverDirectCuSolverRf.cpp | 4 ++++ resolve/LinSolverDirectRocSolverRf.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index c343f8b91..882ebeab9 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -79,6 +79,7 @@ namespace ReSolve if (setup_completed_) { out::error() << "LinSolverDirectCuSolverRf::setup should only be called one." << std::endl; + return 1; } if (d_P_ == nullptr) @@ -88,6 +89,7 @@ namespace ReSolve else { out::error() << "d_P_ should be nullptr on call to LinSolverDirectCuSolverRf::setup." << std::endl; + return 1; } if (d_Q_ == nullptr) @@ -97,6 +99,7 @@ namespace ReSolve else { out::error() << "d_Q_ should be nullptr on call to LinSolverDirectCuSolverRf::setup." << std::endl; + return 1; } if (d_T_ == nullptr) @@ -106,6 +109,7 @@ namespace ReSolve else { out::error() << "d_T_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" << std::endl; + return 1; } mem_.copyArrayHostToDevice(d_P_, P, n); diff --git a/resolve/LinSolverDirectRocSolverRf.cpp b/resolve/LinSolverDirectRocSolverRf.cpp index eb03958c9..d698a6250 100644 --- a/resolve/LinSolverDirectRocSolverRf.cpp +++ b/resolve/LinSolverDirectRocSolverRf.cpp @@ -85,6 +85,7 @@ namespace ReSolve else { out::error() << "d_P_ should be nullptr on call to LinSolverDirectRocSolverRf::setup." << std::endl; + return 1; } if (d_Q_ == nullptr) @@ -94,6 +95,7 @@ namespace ReSolve else { out::error() << "d_Q_ should be nullptr on call to LinSolverDirectRocSolverRf::setup." << std::endl; + return 1; } mem_.copyArrayHostToDevice(d_P_, P, n); mem_.copyArrayHostToDevice(d_Q_, Q, n); From 335cc6939c83c7b057b98092c4358fb7aa67cb9f Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 11 Nov 2025 12:43:28 -0500 Subject: [PATCH 11/14] addressed review comments --- resolve/LinSolverDirectCuSolverRf.cpp | 8 ++++---- resolve/LinSolverDirectRocSolverRf.cpp | 4 ++-- resolve/SystemSolver.cpp | 9 ++++++--- resolve/matrix/io.cpp | 4 ++-- resolve/vector/Vector.cpp | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index 882ebeab9..72b66d310 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -78,7 +78,7 @@ namespace ReSolve if (setup_completed_) { - out::error() << "LinSolverDirectCuSolverRf::setup should only be called one." << std::endl; + out::error() << "Trying to setup LinSolverDirectCuSolverRf, but the setup has been already done! " << std::endl; return 1; } @@ -88,7 +88,7 @@ namespace ReSolve } else { - out::error() << "d_P_ should be nullptr on call to LinSolverDirectCuSolverRf::setup." << std::endl; + out::error() << "Trying to allocate permutation vector P in " << __func__ << " in LinSolverDirectCuSolverRf, but the permutation vector P is already allocated! " << std::endl; return 1; } @@ -98,7 +98,7 @@ namespace ReSolve } else { - out::error() << "d_Q_ should be nullptr on call to LinSolverDirectCuSolverRf::setup." << std::endl; + out::error() << "Trying to allocate permutation vector Q in " << __func__ << " in LinSolverDirectCuSolverRf, but the permutation vector Q is already allocated! " << std::endl; return 1; } @@ -108,7 +108,7 @@ namespace ReSolve } else { - out::error() << "d_T_ should be nullptr on call to LinSolverDirectCuSolverRf::setup" << std::endl; + out::error() << "Trying to allocate temporary vector T in " << __func__ << " in LinSolverDirectCuSolverRf, but the temporary vector T is already allocated! " << std::endl; return 1; } diff --git a/resolve/LinSolverDirectRocSolverRf.cpp b/resolve/LinSolverDirectRocSolverRf.cpp index d698a6250..c2481d6dd 100644 --- a/resolve/LinSolverDirectRocSolverRf.cpp +++ b/resolve/LinSolverDirectRocSolverRf.cpp @@ -84,7 +84,7 @@ namespace ReSolve } else { - out::error() << "d_P_ should be nullptr on call to LinSolverDirectRocSolverRf::setup." << std::endl; + out::error() << "Trying to allocate permutation vector P in " << __func__ << " in LinSolverDirectRocSolverRf, but the permutation vector P is already allocated! " << std::endl; return 1; } @@ -94,7 +94,7 @@ namespace ReSolve } else { - out::error() << "d_Q_ should be nullptr on call to LinSolverDirectRocSolverRf::setup." << std::endl; + out::error() << "Trying to allocate permutation vector Q in " << __func__ << " in LinSolverDirectRocSolverRf, but the permutation vector Q is already allocated! " << std::endl; return 1; } mem_.copyArrayHostToDevice(d_P_, P, n); diff --git a/resolve/SystemSolver.cpp b/resolve/SystemSolver.cpp index 0abd0423a..a714753cc 100644 --- a/resolve/SystemSolver.cpp +++ b/resolve/SystemSolver.cpp @@ -389,7 +389,8 @@ namespace ReSolve factorizationSolver_->setup(A_); return factorizationSolver_->analyze(); } - out::error() << "Analyze method not set to a valid method!" << std::endl; + out::error() << "Analysis method " << factorizationSolver_ << " not recognized!\n" + << "Available options: klu.\n"; return 1; } @@ -405,7 +406,8 @@ namespace ReSolve is_solve_on_device_ = false; return factorizationSolver_->factorize(); } - out::error() << "Factorization method not set to a valid method!" << std::endl; + out::error() << "Factorization method << factorizationSolver_ << not recognized!\n" + << "Available options: klu.\n"; return 1; } @@ -425,7 +427,8 @@ namespace ReSolve is_solve_on_device_ = true; return refactorizationSolver_->refactorize(); } - out::error() << "Refactorization method not set to a valid method!" << std::endl; + out::error() << "Refactorization method " << refactorizationSolver_ << " not recognized!\n" + << "Available options: klu, glu, cusolverrf, rocsolverrf.\n"; return 1; } diff --git a/resolve/matrix/io.cpp b/resolve/matrix/io.cpp index ffcdf5cfc..614fc6425 100644 --- a/resolve/matrix/io.cpp +++ b/resolve/matrix/io.cpp @@ -383,12 +383,12 @@ namespace ReSolve { if (!file) { - Logger::error() << "Empty input to updateArrayFromFile function ..." << std::endl; + Logger::error() << "Empty input to updateArrayFromFile function." << std::endl; return; } if (p_rhs == nullptr) { - Logger::error() << "Null pointer to array in updateArrayFromFile function ..." << std::endl; + Logger::error() << "Memory not allocated for updateArrayFromFile function."<< std::endl; return; } real_type* rhs = *p_rhs; diff --git a/resolve/vector/Vector.cpp b/resolve/vector/Vector.cpp index e503c2f20..e2021771e 100644 --- a/resolve/vector/Vector.cpp +++ b/resolve/vector/Vector.cpp @@ -691,7 +691,7 @@ namespace ReSolve case DEVICE: if (d_data_ == nullptr) { - out::error() << "Trying to set vector device values, but the values are not allocated!" << std::endl; + out::error() << "Trying to set vector values on the device, but the memory is not allocated!" << std::endl; return 1; } mem_.setArrayToConstOnDevice(&d_data_[n_size_ * j], constant, n_size_); From e6822bb680bdb908561711358489b21bba9841c3 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 11 Nov 2025 12:49:18 -0500 Subject: [PATCH 12/14] straggling changes --- resolve/vector/Vector.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resolve/vector/Vector.cpp b/resolve/vector/Vector.cpp index e2021771e..25412ad80 100644 --- a/resolve/vector/Vector.cpp +++ b/resolve/vector/Vector.cpp @@ -681,7 +681,8 @@ namespace ReSolve case HOST: if (h_data_ == nullptr) { - out::error() << "Trying to set vector host values, but the values are not allocated!" << std::endl; + out::error() << "In Vector setToConst: trying to set host data to constant, " + << "but host data not allocated!" << std::endl; return 1; } mem_.setArrayToConstOnHost(&h_data_[n_size_ * j], constant, n_size_); @@ -691,7 +692,8 @@ namespace ReSolve case DEVICE: if (d_data_ == nullptr) { - out::error() << "Trying to set vector values on the device, but the memory is not allocated!" << std::endl; + out::error() << "In Vector setToConst: trying to set device data to constant, " + << "but device data not allocated!" << std::endl; return 1; } mem_.setArrayToConstOnDevice(&d_data_[n_size_ * j], constant, n_size_); From 4d5f92d810fc0d969286644ead95d28ed1cd0533 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Tue, 11 Nov 2025 17:50:05 +0000 Subject: [PATCH 13/14] Apply pre-commmit fixes --- resolve/matrix/io.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolve/matrix/io.cpp b/resolve/matrix/io.cpp index 614fc6425..e6f9fab98 100644 --- a/resolve/matrix/io.cpp +++ b/resolve/matrix/io.cpp @@ -388,7 +388,7 @@ namespace ReSolve } if (p_rhs == nullptr) { - Logger::error() << "Memory not allocated for updateArrayFromFile function."<< std::endl; + Logger::error() << "Memory not allocated for updateArrayFromFile function." << std::endl; return; } real_type* rhs = *p_rhs; From 98a06ac84a4be5e0ef80f1a6629c64ab152a66f9 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Wed, 12 Nov 2025 21:41:25 +0000 Subject: [PATCH 14/14] fixed examples --- examples/gluRefactor.cpp | 9 ++++++++- examples/gpuRefactor.cpp | 2 +- examples/kluFactor.cpp | 10 ++++++++-- examples/kluRefactor.cpp | 9 ++++++++- examples/randGmres.cpp | 2 +- examples/sysRefactor.cpp | 9 ++++++++- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/examples/gluRefactor.cpp b/examples/gluRefactor.cpp index 322b392ba..3b1cbc6c9 100644 --- a/examples/gluRefactor.cpp +++ b/examples/gluRefactor.cpp @@ -264,7 +264,14 @@ int gluRefactor(int argc, char* argv[]) RESOLVE_RANGE_POP("Triangular solve"); // Print summary of the results - helper.resetSystem(A, vec_rhs, vec_x); + if (i == 0) + { + helper.setSystem(A, vec_rhs, vec_x); + } + else + { + helper.resetSystem(A, vec_rhs, vec_x); + } helper.printSummary(); } // for (int i = 0; i < num_systems; ++i) diff --git a/examples/gpuRefactor.cpp b/examples/gpuRefactor.cpp index 90f5ee06e..39f0dcc01 100644 --- a/examples/gpuRefactor.cpp +++ b/examples/gpuRefactor.cpp @@ -260,7 +260,7 @@ int gpuRefactor(int argc, char* argv[]) std::cout << "KLU solve status: " << status << std::endl; // Print summary of results - helper.resetSystem(A, vec_rhs, vec_x); + helper.setSystem(A, vec_rhs, vec_x); helper.printShortSummary(); if (i == 1) diff --git a/examples/kluFactor.cpp b/examples/kluFactor.cpp index 78ad54d50..e119af39d 100644 --- a/examples/kluFactor.cpp +++ b/examples/kluFactor.cpp @@ -184,8 +184,14 @@ int main(int argc, char* argv[]) status = KLU.solve(vec_rhs, vec_x); std::cout << "KLU solve status: " << status << std::endl; - - helper.resetSystem(A, vec_rhs, vec_x); + if (i == 0) + { + helper.setSystem(A, vec_rhs, vec_x); + } + else + { + helper.resetSystem(A, vec_rhs, vec_x); + } helper.printShortSummary(); if (is_iterative_refinement) { diff --git a/examples/kluRefactor.cpp b/examples/kluRefactor.cpp index ddf188d4a..8325b5e12 100644 --- a/examples/kluRefactor.cpp +++ b/examples/kluRefactor.cpp @@ -191,7 +191,14 @@ int main(int argc, char* argv[]) status = KLU->solve(vec_rhs, vec_x); std::cout << "KLU solve status: " << status << std::endl; - helper.resetSystem(A, vec_rhs, vec_x); + if (i == 0) + { + helper.setSystem(A, vec_rhs, vec_x); + } + else + { + helper.resetSystem(A, vec_rhs, vec_x); + } helper.printShortSummary(); if (is_iterative_refinement) { diff --git a/examples/randGmres.cpp b/examples/randGmres.cpp index 629cc2649..440b4031c 100644 --- a/examples/randGmres.cpp +++ b/examples/randGmres.cpp @@ -183,7 +183,7 @@ int runGmresExample(int argc, char* argv[]) FGMRES.solve(vec_rhs, vec_x); // Print summary of results - helper.resetSystem(A, vec_rhs, vec_x); + helper.setSystem(A, vec_rhs, vec_x); std::cout << "\nRandomized GMRES result on " << hwbackend << "\n"; std::cout << "---------------------------------\n"; helper.printIrSummary(&FGMRES); diff --git a/examples/sysRefactor.cpp b/examples/sysRefactor.cpp index 3a095213c..509a8efbc 100644 --- a/examples/sysRefactor.cpp +++ b/examples/sysRefactor.cpp @@ -320,7 +320,14 @@ int sysRefactor(int argc, char* argv[]) std::cout << "Triangular solve status: " << status << std::endl; // Print summary of results - helper.resetSystem(A, vec_rhs, vec_x); + if (i == 0) + { + helper.setSystem(A, vec_rhs, vec_x); + } + else + { + helper.resetSystem(A, vec_rhs, vec_x); + } helper.printShortSummary(); if ((i > 1) && is_iterative_refinement) {