Skip to content

Commit

Permalink
fixes for inf norm + larger lena
Browse files Browse the repository at this point in the history
  • Loading branch information
superwhiskers committed Jul 30, 2024
1 parent 1cb7134 commit 90316ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions examples/r_LUSOL_LUSOL.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <chrono>
#include <cmath>
#include <filesystem>
Expand All @@ -22,13 +23,29 @@ using real_type = ReSolve::real_type;
using vector_type = ReSolve::vector::Vector;
using std::chrono::steady_clock;

int specializedInfNorm(ReSolve::matrix::Coo* A,
real_type* norm)
{

std::unique_ptr<index_type[]> sums = std::unique_ptr<index_type[]>(new index_type[A->getNumRows()]);

index_type* rows = A->getRowData(ReSolve::memory::HOST);
real_type* values = A->getValues(ReSolve::memory::HOST);

for (index_type i = 0; i < A->getNnz(); i++) {
sums[rows[i]] += std::abs(values[i]);
}

*norm = *std::max_element(sums.get(), sums.get() + A->getNumRows());
return 0;
}

int specializedMatvec(ReSolve::matrix::Coo* Ageneric,
vector_type* vec_x,
vector_type* vec_result,
const real_type* alpha,
const real_type* beta)
{

ReSolve::matrix::Coo* A = static_cast<ReSolve::matrix::Coo*>(Ageneric);
index_type* rows = A->getRowData(ReSolve::memory::HOST);
index_type* columns = A->getColData(ReSolve::memory::HOST);
Expand Down Expand Up @@ -96,7 +113,6 @@ int main(int argc, char* argv[])

for (int system = 0; system < n_systems; system++) {
std::unique_ptr<ReSolve::LinAlgWorkspaceCpu> workspace(new ReSolve::LinAlgWorkspaceCpu());
std::unique_ptr<ReSolve::MatrixHandler> matrix_handler(new ReSolve::MatrixHandler(workspace.get()));
std::unique_ptr<ReSolve::VectorHandler> vector_handler(new ReSolve::VectorHandler(workspace.get()));
std::unique_ptr<ReSolve::LinSolverDirectLUSOL> lusol(new ReSolve::LinSolverDirectLUSOL);

Expand Down Expand Up @@ -187,12 +203,10 @@ int main(int argc, char* argv[])

vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);

matrix_handler->setValuesChanged(true, ReSolve::memory::HOST);

specializedMatvec(A.get(), vec_x.get(), vec_r.get(), &ONE, &MINUSONE);
norm_r = vector_handler->infNorm(vec_r.get(), ReSolve::memory::HOST);

matrix_handler->matrixInfNorm(A.get(), &norm_A, ReSolve::memory::HOST);
specializedInfNorm(A.get(), &norm_A);
norm_x = vector_handler->infNorm(vec_x.get(), ReSolve::memory::HOST);

output << std::setprecision(16) << std::scientific
Expand Down
2 changes: 1 addition & 1 deletion resolve/LinSolverDirectLUSOL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ namespace ReSolve
} else {
lena_ = std::min(5 * nelem_, 2 * m_ * n_);
}*/
lena_ = 3000000;
lena_ = 10000000;

a_ = new real_type[lena_];
indc_ = new index_type[lena_];
Expand Down

0 comments on commit 90316ea

Please sign in to comment.