Skip to content

Commit

Permalink
Use enums instead of strings to denote memory space (#42)
Browse files Browse the repository at this point in the history
* Use enums for memory space ID in matrix classes.

* Use enums for vector class memory space IDs.
  • Loading branch information
pelesh authored Nov 1, 2023
1 parent 7ea6515 commit 949680f
Show file tree
Hide file tree
Showing 39 changed files with 898 additions and 827 deletions.
12 changes: 6 additions & 6 deletions examples/r_KLU_GLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ int main(int argc, char *argv[])
x = new real_type[A->getNumRows()];
vec_rhs = new vector_type(A->getNumRows());
vec_x = new vector_type(A->getNumRows());
vec_x->allocate("cpu");//for KLU
vec_x->allocate("cuda");
vec_x->allocate(ReSolve::memory::HOST);//for KLU
vec_x->allocate(ReSolve::memory::DEVICE);
vec_r = new vector_type(A->getNumRows());
} else {
ReSolve::io::readAndUpdateMatrix(mat_file, A_coo);
Expand All @@ -107,11 +107,11 @@ int main(int argc, char *argv[])
//Now convert to CSR.
if (i < 1) {
matrix_handler->coo2csr(A_coo, A, "cpu");
vec_rhs->update(rhs, "cpu", "cpu");
vec_rhs->setDataUpdated("cpu");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);
vec_rhs->setDataUpdated(ReSolve::memory::HOST);
} else {
matrix_handler->coo2csr(A_coo, A, "cuda");
vec_rhs->update(rhs, "cpu", "cuda");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
Expand Down Expand Up @@ -143,7 +143,7 @@ int main(int argc, char *argv[])
status = GLU->solve(vec_rhs, vec_x);
std::cout<<"CUSOLVER GLU solve status: "<<status<<std::endl;
}
vec_r->update(rhs, "cpu", "cuda");
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);


matrix_handler->setValuesChanged(true, "cuda");
Expand Down
14 changes: 7 additions & 7 deletions examples/r_KLU_GLU_matrix_values_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ int main(int argc, char *argv[])
x = new real_type[A->getNumRows()];
vec_rhs = new vector_type(A->getNumRows());
vec_x = new vector_type(A->getNumRows());
vec_x->allocate("cpu");//for KLU
vec_x->allocate("cuda");
vec_x->allocate(ReSolve::memory::HOST);//for KLU
vec_x->allocate(ReSolve::memory::DEVICE);
vec_r = new vector_type(A->getNumRows());
} else {
if (i==1) {
Expand All @@ -106,7 +106,7 @@ int main(int argc, char *argv[])
ReSolve::io::readAndUpdateMatrix(mat_file, A_exp_coo);
}
std::cout<<"Updating values of A_coo!"<<std::endl;
A_coo->updateValues(A_exp_coo->getValues("cpu"), "cpu", "cpu");
A_coo->updateValues(A_exp_coo->getValues(ReSolve::memory::HOST), ReSolve::memory::HOST, ReSolve::memory::HOST);
//ReSolve::io::readAndUpdateMatrix(mat_file, A_coo);
ReSolve::io::readAndUpdateRhs(rhs_file, &rhs);
}
Expand All @@ -117,11 +117,11 @@ int main(int argc, char *argv[])
//Now convert to CSR.
if (i < 1) {
matrix_handler->coo2csr(A_coo, A, "cpu");
vec_rhs->update(rhs, "cpu", "cpu");
vec_rhs->setDataUpdated("cpu");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);
vec_rhs->setDataUpdated(ReSolve::memory::HOST);
} else {
matrix_handler->coo2csr(A_coo, A, "cuda");
vec_rhs->update(rhs, "cpu", "cuda");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
Expand Down Expand Up @@ -153,7 +153,7 @@ int main(int argc, char *argv[])
status = GLU->solve(vec_rhs, vec_x);
std::cout<<"CUSOLVER GLU solve status: "<<status<<std::endl;
}
vec_r->update(rhs, "cpu", "cuda");
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);


matrix_handler->setValuesChanged(true, "cuda");
Expand Down
8 changes: 4 additions & 4 deletions examples/r_KLU_KLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ int main(int argc, char *argv[])
//Now convert to CSR.
if (i < 2) {
matrix_handler->coo2csr(A_coo, A, "cpu");
vec_rhs->update(rhs, "cpu", "cpu");
vec_rhs->setDataUpdated("cpu");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);
vec_rhs->setDataUpdated(ReSolve::memory::HOST);
} else {
matrix_handler->coo2csr(A_coo, A, "cpu");
vec_rhs->update(rhs, "cpu", "cpu");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
Expand All @@ -134,7 +134,7 @@ int main(int argc, char *argv[])
status = KLU->solve(vec_rhs, vec_x);
std::cout<<"KLU solve status: "<<status<<std::endl;
}
vec_r->update(rhs, "cpu", "cpu");
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);

matrix_handler->setValuesChanged(true, "cpu");

Expand Down
6 changes: 3 additions & 3 deletions examples/r_KLU_KLU_standalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ int main(int argc, char *argv[])

//Now convert to CSR.
matrix_handler->coo2csr(A_coo, A, "cpu");
vec_rhs->update(rhs, "cpu", "cpu");
vec_rhs->setDataUpdated("cpu");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);
vec_rhs->setDataUpdated(ReSolve::memory::HOST);
std::cout << "COO to CSR completed. Expanded NNZ: " << A->getNnzExpanded() << std::endl;
//Now call direct solver
KLU->setupParameters(1, 0.1, false);
Expand All @@ -96,7 +96,7 @@ int main(int argc, char *argv[])
std::cout << "KLU factorization status: " << status << std::endl;
status = KLU->solve(vec_rhs, vec_x);
std::cout << "KLU solve status: " << status << std::endl;
vec_r->update(rhs, "cpu", "cpu");
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);

matrix_handler->setValuesChanged(true, "cpu");

Expand Down
8 changes: 4 additions & 4 deletions examples/r_KLU_rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ int main(int argc, char *argv[] )
//Now convert to CSR.
if (i < 2) {
matrix_handler->coo2csr(A_coo, A, "cpu");
vec_rhs->update(rhs, "cpu", "cpu");
vec_rhs->setDataUpdated("cpu");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);
vec_rhs->setDataUpdated(ReSolve::memory::HOST);
} else {
matrix_handler->coo2csr(A_coo, A, "cuda");
vec_rhs->update(rhs, "cpu", "cuda");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
Expand Down Expand Up @@ -157,7 +157,7 @@ int main(int argc, char *argv[] )
//status = KLU->solve(vec_rhs, vec_x);
//std::cout<<"KLU solve status: "<<status<<std::endl;
}
vec_r->update(rhs, "cpu", "cuda");
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);

matrix_handler->setValuesChanged(true, "cuda");

Expand Down
18 changes: 9 additions & 9 deletions examples/r_KLU_rf_FGMRES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ int main(int argc, char *argv[])
x = new real_type[A->getNumRows()];
vec_rhs = new vector_type(A->getNumRows());
vec_x = new vector_type(A->getNumRows());
vec_x->allocate("cpu");//for KLU
vec_x->allocate("cuda");
vec_x->allocate(ReSolve::memory::HOST);//for KLU
vec_x->allocate(ReSolve::memory::DEVICE);
vec_r = new vector_type(A->getNumRows());
}
else {
Expand All @@ -111,11 +111,11 @@ int main(int argc, char *argv[])
//Now convert to CSR.
if (i < 2) {
matrix_handler->coo2csr(A_coo, A, "cpu");
vec_rhs->update(rhs, "cpu", "cpu");
vec_rhs->setDataUpdated("cpu");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);
vec_rhs->setDataUpdated(ReSolve::memory::HOST);
} else {
matrix_handler->coo2csr(A_coo,A, "cuda");
vec_rhs->update(rhs, "cpu", "cuda");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
Expand All @@ -133,7 +133,7 @@ int main(int argc, char *argv[])
std::cout<<"KLU factorization status: "<<status<<std::endl;
status = KLU->solve(vec_rhs, vec_x);
std::cout<<"KLU solve status: "<<status<<std::endl;
vec_r->update(rhs, "cpu", "cuda");
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
norm_b = vector_handler->dot(vec_r, vec_r, "cuda");
norm_b = sqrt(norm_b);
matrix_handler->setValuesChanged(true, "cuda");
Expand Down Expand Up @@ -162,8 +162,8 @@ int main(int argc, char *argv[])
status = Rf->solve(vec_rhs, vec_x);
std::cout<<"CUSOLVER RF solve status: "<<status<<std::endl;

vec_r->update(rhs, "cpu", "cuda");
norm_b = vector_handler->dot(vec_r, vec_r, "cuda");
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
norm_b = vector_handler->dot(vec_r, vec_r, "cuda");
norm_b = sqrt(norm_b);

//matrix_handler->setValuesChanged(true, "cuda");
Expand All @@ -176,7 +176,7 @@ int main(int argc, char *argv[])
<< std::scientific << std::setprecision(16)
<< sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))/norm_b << "\n";

vec_rhs->update(rhs, "cpu", "cuda");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
FGMRES->solve(vec_rhs, vec_x);

std::cout << "FGMRES: init nrm: "
Expand Down
24 changes: 12 additions & 12 deletions examples/r_KLU_rf_FGMRES_reuse_factorization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ int main(int argc, char *argv[])
x = new real_type[A->getNumRows()];
vec_rhs = new vector_type(A->getNumRows());
vec_x = new vector_type(A->getNumRows());
vec_x->allocate("cpu");//for KLU
vec_x->allocate("cuda");
vec_x->allocate(ReSolve::memory::HOST);//for KLU
vec_x->allocate(ReSolve::memory::DEVICE);
vec_r = new vector_type(A->getNumRows());
}
else {
Expand All @@ -113,11 +113,11 @@ int main(int argc, char *argv[])
//Now convert to CSR.
if (i < 2) {
matrix_handler->coo2csr(A_coo,A, "cpu");
vec_rhs->update(rhs, "cpu", "cpu");
vec_rhs->setDataUpdated("cpu");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::HOST);
vec_rhs->setDataUpdated(ReSolve::memory::HOST);
} else {
matrix_handler->coo2csr(A_coo, A, "cuda");
vec_rhs->update(rhs, "cpu", "cuda");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
Expand All @@ -135,7 +135,7 @@ int main(int argc, char *argv[])
std::cout<<"KLU factorization status: "<<status<<std::endl;
status = KLU->solve(vec_rhs, vec_x);
std::cout<<"KLU solve status: "<<status<<std::endl;
vec_r->update(rhs, "cpu", "cuda");
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
norm_b = vector_handler->dot(vec_r, vec_r, "cuda");
norm_b = sqrt(norm_b);
matrix_handler->setValuesChanged(true, "cuda");
Expand Down Expand Up @@ -171,20 +171,20 @@ int main(int argc, char *argv[])
status = Rf->refactorize();
std::cout << "CUSOLVER RF, using REAL refactorization, refactorization status: "
<< status << std::endl;
vec_rhs->update(rhs, "cpu", "cuda");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
status = Rf->solve(vec_rhs, vec_x);
FGMRES->setupPreconditioner("CuSolverRf", Rf);
}
//if (i%2!=0) vec_x->setToZero("cuda");
//if (i%2!=0) vec_x->setToZero(ReSolve::memory::DEVICE);
real_type norm_x = vector_handler->dot(vec_x, vec_x, "cuda");
std::cout << "Norm of x (before solve): "
<< std::scientific << std::setprecision(16)
<< sqrt(norm_x) << "\n";
std::cout<<"CUSOLVER RF solve status: "<<status<<std::endl;

vec_rhs->update(rhs, "cpu", "cuda");
vec_r->update(rhs, "cpu", "cuda");
norm_b = vector_handler->dot(vec_r, vec_r, "cuda");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
norm_b = vector_handler->dot(vec_r, vec_r, "cuda");
norm_b = sqrt(norm_b);

matrix_handler->setValuesChanged(true, "cuda");
Expand All @@ -199,7 +199,7 @@ int main(int argc, char *argv[])
<< std::scientific << std::setprecision(16)
<< norm_b << "\n";

vec_rhs->update(rhs, "cpu", "cuda");
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
FGMRES->solve(vec_rhs, vec_x);

std::cout << "FGMRES: init nrm: "
Expand Down
Loading

0 comments on commit 949680f

Please sign in to comment.