Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enums instead of strings to denote memory space #42

Merged
merged 6 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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