Skip to content

Commit

Permalink
use L_ and U_, constrain size of U by nsing
Browse files Browse the repository at this point in the history
  • Loading branch information
superwhiskers committed Jul 22, 2024
1 parent 88405f4 commit c8deb1e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
56 changes: 41 additions & 15 deletions resolve/LinSolverDirectLUSOL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ namespace ReSolve
vector_type* /* rhs */)
{
A_ = A;
is_factorized_ = false;
delete L_;
delete U_;
L_ = nullptr;
U_ = nullptr;
return 0;
}

Expand Down Expand Up @@ -154,6 +159,8 @@ namespace ReSolve
w_,
&inform);

is_factorized_ = true;

// TODO: consider handling inform = 7

return inform;
Expand All @@ -168,7 +175,7 @@ namespace ReSolve

int LinSolverDirectLUSOL::solve(vector_type* rhs, vector_type* x)
{
if (rhs->getSize() != m_ || x->getSize() != n_) {
if (rhs->getSize() != m_ || x->getSize() != n_ || !is_factorized_) {
return -1;
}

Expand Down Expand Up @@ -206,15 +213,27 @@ namespace ReSolve

matrix::Sparse* LinSolverDirectLUSOL::getLFactor()
{
if (!is_factorized_) {
return nullptr;
}

if (L_ != nullptr) {
// by the way we've implemented setup, we can just return the
// existing pointer in L_ as this means we've already extracted L
//
// this isn't perfect, but it's functional
return L_;
}

index_type diagonal_bound = std::min({m_, n_});

matrix::Csc* L = new matrix::Csc(n_, m_, luparm_[22] + diagonal_bound, false, true);
L->allocateMatrixData(memory::HOST);
L_ = static_cast<matrix::Sparse*>(new matrix::Csc(n_, m_, luparm_[22] + diagonal_bound, false, true));
L_->allocateMatrixData(memory::HOST);

index_type* columns = L->getColData(memory::HOST);
index_type* rows = L->getRowData(memory::HOST);
index_type* columns = L_->getColData(memory::HOST);
index_type* rows = L_->getRowData(memory::HOST);
std::fill_n(rows, luparm_[22], -1);
real_type* values = L->getValues(memory::HOST);
real_type* values = L_->getValues(memory::HOST);

// build an inverse permutation array for p

Expand Down Expand Up @@ -249,8 +268,6 @@ namespace ReSolve
}

// fill the destination arrays
// TODO: use the already allocated L_ and U_ matrices instead of allocating new ones
// TODO: size appears to be constrained by nsing

offset = lena_ - 1;
for (index_type i = 0; i < luparm_[19]; i++) {
Expand Down Expand Up @@ -288,18 +305,27 @@ namespace ReSolve
}
}

return static_cast<matrix::Sparse*>(L);
return L_;
}

matrix::Sparse* LinSolverDirectLUSOL::getUFactor()
{
matrix::Csr* U = new matrix::Csr(n_, m_, luparm_[23], false, true);
U->allocateMatrixData(memory::HOST);
if (!is_factorized_) {
return nullptr;
}

if (U_ != nullptr) {
// likewise
return U_;
}

U_ = static_cast<matrix::Sparse*>(new matrix::Csr(n_, m_, luparm_[23] - luparm_[10], false, true));
U_->allocateMatrixData(memory::HOST);

index_type* rows = U->getRowData(memory::HOST);
index_type* columns = U->getColData(memory::HOST);
index_type* rows = U_->getRowData(memory::HOST);
index_type* columns = U_->getColData(memory::HOST);
std::fill_n(columns, luparm_[23], -1);
real_type* values = U->getValues(memory::HOST);
real_type* values = U_->getValues(memory::HOST);

// build an inverse permutation array for q

Expand Down Expand Up @@ -357,7 +383,7 @@ namespace ReSolve
}
}

return static_cast<matrix::Sparse*>(U);
return U_;
}

index_type* LinSolverDirectLUSOL::getPOrdering()
Expand Down
3 changes: 3 additions & 0 deletions resolve/LinSolverDirectLUSOL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace ReSolve

MemoryHandler mem_;

/// @brief Indicates if we have factorized the matrix yet
bool is_factorized_ = false;

/// @brief Storage used for the matrices
///
/// Primary workspace used by LUSOL. Used to hold the nonzeros of matrices
Expand Down

0 comments on commit c8deb1e

Please sign in to comment.