Skip to content

Commit

Permalink
Fix warnings in solver classes. (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
pelesh authored Nov 3, 2023
1 parent 1a6f9c1 commit 1ed777f
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 38 deletions.
17 changes: 11 additions & 6 deletions examples/r_KLU_rocSolverRf_FGMRES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,8 @@ int main(int argc, char *argv[])
matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE,"csr", "hip");
printf("\t 2-Norm of the residual : %16.16e\n", sqrt(vector_handler->dot(vec_r, vec_r, "hip"))/norm_b);
if (i == 1) {
ReSolve::matrix::Csc* L /* _csc */ = (ReSolve::matrix::Csc*) KLU->getLFactor();
ReSolve::matrix::Csc* U /* _csc */ = (ReSolve::matrix::Csc*) KLU->getUFactor();
// ReSolve::matrix::Csr* L = new ReSolve::matrix::Csr(L_csc->getNumRows(), L_csc->getNumColumns(), L_csc->getNnz());
// ReSolve::matrix::Csr* U = new ReSolve::matrix::Csr(U_csc->getNumRows(), U_csc->getNumColumns(), U_csc->getNnz());
// matrix_handler->csc2csr(L_csc,L, "hip");
// matrix_handler->csc2csr(U_csc,U, "hip");
ReSolve::matrix::Csc* L = (ReSolve::matrix::Csc*) KLU->getLFactor();
ReSolve::matrix::Csc* U = (ReSolve::matrix::Csc*) KLU->getUFactor();
if (L == nullptr) {printf("ERROR");}
index_type* P = KLU->getPOrdering();
index_type* Q = KLU->getQOrdering();
Expand Down Expand Up @@ -193,8 +189,17 @@ int main(int argc, char *argv[])

} // for (int i = 0; i < numSystems; ++i)

delete A;
delete A_coo;
delete KLU;
delete Rf;
delete [] x;
delete [] rhs;
delete vec_r;
delete vec_x;
delete workspace_HIP;
delete matrix_handler;
delete vector_handler;

return 0;
}
8 changes: 1 addition & 7 deletions examples/r_KLU_rocsolverrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,13 @@ int main(int argc, char *argv[] )
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
Rf->setup(A, L, U, P, Q, vec_rhs);
Rf->refactorize();
//dont do it here
// delete [] P;
// delete [] Q;
}
} else {
//status = KLU->refactorize();
std::cout<<"Using rocsolver rf"<<std::endl;
status = Rf->refactorize();
std::cout<<"rocsolver rf refactorization status: "<<status<<std::endl;
status = Rf->solve(vec_rhs, vec_x);
std::cout<<"rocsolver rf solve status: "<<status<<std::endl;
//std::cout<<"KLU re-factorization status: "<<status<<std::endl;
//status = KLU->solve(vec_rhs, vec_x);
//std::cout<<"KLU solve status: "<<status<<std::endl;
}
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);

Expand All @@ -164,6 +157,7 @@ int main(int argc, char *argv[] )

//now DELETE
delete A;
delete A_coo;
delete KLU;
delete Rf;
delete [] x;
Expand Down
22 changes: 16 additions & 6 deletions resolve/LinSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ namespace ReSolve
//destroy the matrix and hadlers
}

int LinSolver::setup(matrix::Sparse* A)
{
this->A_ = A;
return 0;
}

real_type LinSolver::evaluateResidual()
{
//to be implemented
Expand All @@ -42,6 +36,17 @@ namespace ReSolve
delete [] Q_;
}

int LinSolverDirect::setup(matrix::Sparse* A,
matrix::Sparse* /* L */,
matrix::Sparse* /* U */,
index_type* /* P */,
index_type* /* Q */,
vector_type* /* rhs */)
{
this->A_ = A;
return 0;
}

int LinSolverDirect::analyze()
{
return 0;
Expand Down Expand Up @@ -92,6 +97,11 @@ namespace ReSolve
{
}

int LinSolverIterative::setup(matrix::Sparse* A)
{
this->A_ = A;
return 0;
}

int LinSolverIterative::solve(vector_type* /* rhs */, vector_type* /* init_guess */)
{
Expand Down
9 changes: 8 additions & 1 deletion resolve/LinSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace ReSolve
LinSolver();
virtual ~LinSolver();

virtual int setup(matrix::Sparse* A);
real_type evaluateResidual();

protected:
Expand All @@ -49,6 +48,13 @@ namespace ReSolve
LinSolverDirect();
virtual ~LinSolverDirect();
//return 0 if successful!
virtual int setup(matrix::Sparse* A,
matrix::Sparse* L,
matrix::Sparse* U,
index_type* P,
index_type* Q,
vector_type* rhs);

virtual int analyze(); //the same as symbolic factorization
virtual int factorize();
virtual int refactorize();
Expand All @@ -72,6 +78,7 @@ namespace ReSolve
public:
LinSolverIterative();
~LinSolverIterative();
virtual int setup(matrix::Sparse* A);

virtual int solve(vector_type* rhs, vector_type* init_guess);
};
Expand Down
9 changes: 8 additions & 1 deletion resolve/LinSolverDirectCuSolverGLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace ReSolve
{
using vector_type = vector::Vector;

LinSolverDirectCuSolverGLU::LinSolverDirectCuSolverGLU(LinAlgWorkspaceCUDA* workspace)
{
this->workspace_ = workspace;
Expand All @@ -22,7 +24,12 @@ namespace ReSolve
delete M_;
}

int LinSolverDirectCuSolverGLU::setup(matrix::Sparse* A, matrix::Sparse* L, matrix::Sparse* U, index_type* P, index_type* Q)
int LinSolverDirectCuSolverGLU::setup(matrix::Sparse* A,
matrix::Sparse* L,
matrix::Sparse* U,
index_type* P,
index_type* Q,
vector_type* /* rhs */)
{
int error_sum = 0;

Expand Down
7 changes: 6 additions & 1 deletion resolve/LinSolverDirectCuSolverGLU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ namespace ReSolve
int refactorize();
int solve(vector_type* rhs, vector_type* x);

int setup(matrix::Sparse* A, matrix::Sparse* L, matrix::Sparse* U, index_type* P, index_type* Q);
int setup(matrix::Sparse* A,
matrix::Sparse* L,
matrix::Sparse* U,
index_type* P,
index_type* Q,
vector_type* rhs = nullptr);

private:
void addFactors(matrix::Sparse* L, matrix::Sparse* U); //create L+U from sepeate L, U factors
Expand Down
7 changes: 6 additions & 1 deletion resolve/LinSolverDirectCuSolverRf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ namespace ReSolve
mem_.deleteOnDevice(d_T_);
}

int LinSolverDirectCuSolverRf::setup(matrix::Sparse* A, matrix::Sparse* L, matrix::Sparse* U, index_type* P, index_type* Q)
int LinSolverDirectCuSolverRf::setup(matrix::Sparse* A,
matrix::Sparse* L,
matrix::Sparse* U,
index_type* P,
index_type* Q,
vector_type* /* rhs */)
{
//remember - P and Q are generally CPU variables
int error_sum = 0;
Expand Down
7 changes: 6 additions & 1 deletion resolve/LinSolverDirectCuSolverRf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ namespace ReSolve
LinSolverDirectCuSolverRf();
~LinSolverDirectCuSolverRf();

int setup(matrix::Sparse* A, matrix::Sparse* L, matrix::Sparse* U, index_type* P, index_type* Q);
int setup(matrix::Sparse* A,
matrix::Sparse* L,
matrix::Sparse* U,
index_type* P,
index_type* Q,
vector_type* rhs = nullptr);

void setAlgorithms(cusolverRfFactorization_t fact_alg, cusolverRfTriangularSolve_t solve_alg);

Expand Down
7 changes: 6 additions & 1 deletion resolve/LinSolverDirectKLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ namespace ReSolve
klu_free_numeric(&Numeric_, &Common_);
}

int LinSolverDirectKLU::setup(matrix::Sparse* A)
int LinSolverDirectKLU::setup(matrix::Sparse* A,
matrix::Sparse* /* L */,
matrix::Sparse* /* U */,
index_type* /* P */,
index_type* /* Q */,
vector_type* /* rhs */)
{
this->A_ = A;
return 0;
Expand Down
8 changes: 7 additions & 1 deletion resolve/LinSolverDirectKLU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ namespace ReSolve
public:
LinSolverDirectKLU();
~LinSolverDirectKLU();
int setup(matrix::Sparse* A);

int setup(matrix::Sparse* A,
matrix::Sparse* L = nullptr,
matrix::Sparse* U = nullptr,
index_type* P = nullptr,
index_type* Q = nullptr,
vector_type* rhs = nullptr);

void setupParameters(int ordering, double KLU_threshold, bool halt_if_singular);

Expand Down
22 changes: 11 additions & 11 deletions resolve/LinSolverDirectRocSolverRf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ namespace ReSolve
delete U_csr_;
}

int LinSolverDirectRocSolverRf::setup(matrix::Sparse* A, matrix::Sparse* L, matrix::Sparse* U, index_type* P, index_type* Q, vector_type* rhs)
int LinSolverDirectRocSolverRf::setup(matrix::Sparse* A,
matrix::Sparse* L,
matrix::Sparse* U,
index_type* P,
index_type* Q,
vector_type* rhs)
{
//remember - P and Q are generally CPU variables
int error_sum = 0;
Expand Down Expand Up @@ -113,9 +118,6 @@ namespace ReSolve
&L_buffer_size);
error_sum += status_rocsparse_;

printf("buffer size for L %d status %d \n", L_buffer_size, status_rocsparse_);
// hipMalloc((void**)&(L_buffer), L_buffer_size);

mem_.allocateBufferOnDevice(&L_buffer_, L_buffer_size);
status_rocsparse_ = rocsparse_dcsrsv_buffer_size(workspace_->getRocsparseHandle(),
rocsparse_operation_none,
Expand All @@ -128,9 +130,7 @@ namespace ReSolve
info_U_,
&U_buffer_size);
error_sum += status_rocsparse_;
// hipMalloc((void**)&(U_buffer), U_buffer_size);
mem_.allocateBufferOnDevice(&U_buffer_, U_buffer_size);
printf("buffer size for U %d status %d \n", U_buffer_size, status_rocsparse_);

status_rocsparse_ = rocsparse_dcsrsv_analysis(workspace_->getRocsparseHandle(),
rocsparse_operation_none,
Expand Down Expand Up @@ -389,22 +389,22 @@ printf("solve mode 1, splitting the factors again \n");
mia[i] += mia[i - 1];
}

std::vector<int> Mshifts(n, 0);
std::vector<int> Mshifts(static_cast<size_t>(n), 0);
for(index_type i = 0; i < n; ++i) {
// go through EACH COLUMN OF L first
for(int j = Lp[i]; j < Lp[i + 1]; ++j) {
row = Li[j];
if(row != i) {
// place (row, i) where it belongs!
mja[mia[row] + Mshifts[row]] = i;
Mshifts[row]++;
mja[mia[row] + Mshifts[static_cast<size_t>(row)]] = i;
Mshifts[static_cast<size_t>(row)]++;
}
}
// each column of U next
for(index_type j = Up[i]; j < Up[i + 1]; ++j) {
row = Ui[j];
mja[mia[row] + Mshifts[row]] = i;
Mshifts[row]++;
mja[mia[row] + Mshifts[static_cast<size_t>(row)]] = i;
Mshifts[static_cast<size_t>(row)]++;
}
}
//Mshifts.~vector();
Expand Down
7 changes: 6 additions & 1 deletion resolve/LinSolverDirectRocSolverRf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ namespace ReSolve
LinSolverDirectRocSolverRf(LinAlgWorkspaceHIP* workspace);
~LinSolverDirectRocSolverRf();

int setup(matrix::Sparse* A, matrix::Sparse* L, matrix::Sparse* U, index_type* P, index_type* Q, vector_type* rhs);
int setup(matrix::Sparse* A,
matrix::Sparse* L,
matrix::Sparse* U,
index_type* P,
index_type* Q,
vector_type* rhs);

int refactorize();
int solve(vector_type* rhs, vector_type* x);
Expand Down

0 comments on commit 1ed777f

Please sign in to comment.