Skip to content

Commit

Permalink
Merge pull request #119 from cvanaret/ma27
Browse files Browse the repository at this point in the history
MA27: upper bound on factorization attempts
  • Loading branch information
cvanaret authored Dec 2, 2024
2 parents 656a7eb + 20abc3c commit 5943078
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion uno/solvers/MA27/MA27Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project directory for details.

#include <cassert>
#include <stdexcept>
#include "MA27Solver.hpp"
#include "linear_algebra/SymmetricMatrix.hpp"
#include "linear_algebra/Vector.hpp"
Expand Down Expand Up @@ -151,7 +152,7 @@ namespace uno {
}
}

void MA27Solver::do_numerical_factorization([[maybe_unused]]const SymmetricMatrix<size_t, double>& matrix) {
void MA27Solver::do_numerical_factorization([[maybe_unused]] const SymmetricMatrix<size_t, double>& matrix) {
assert(matrix.dimension() <= iw1.capacity() && "MA27Solver: the dimension of the matrix is larger than the preallocated size");
assert(nnz == static_cast<int>(matrix.number_nonzeros()) && "MA27Solver: the numbers of nonzeros do not match");

Expand All @@ -161,7 +162,13 @@ namespace uno {
// numerical factorization
// may fail because of insufficient space. In this case, more memory is allocated and the factorization tried again
bool factorization_done = false;
size_t attempt = 0;
while (not factorization_done) {
attempt++;
if (this->number_factorization_attempts < attempt) {
throw std::runtime_error("MA27 reached the maximum number of factorization attempts");
}

int la = static_cast<int>(factor.size());
int liw = static_cast<int>(iw.size());
MA27BD(&n, &nnz, irn.data(), icn.data(), factor.data(), &la, iw.data(), &liw, ikeep.data(), &nsteps, &maxfrt, iw1.data(), icntl.data(),
Expand Down
1 change: 1 addition & 0 deletions uno/solvers/MA27/MA27Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace uno {
std::vector<double> factor{}; // data array of length la;
int maxfrt{}; // integer, to be set by ma27
std::vector<double> w{}; // double workspace
const size_t number_factorization_attempts{5};


// bool use_iterative_refinement{false}; // Not sure how to do this with ma27
Expand Down

0 comments on commit 5943078

Please sign in to comment.