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

Implement system solver class #86

Merged
merged 11 commits into from
Dec 5, 2023
18 changes: 17 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ target_link_libraries(klu_klu.exe PRIVATE ReSolve)
add_executable(klu_klu_standalone.exe r_KLU_KLU_standalone.cpp)
target_link_libraries(klu_klu_standalone.exe PRIVATE ReSolve)

# Build example with a configurable system solver
add_executable(system.exe r_SysSolver.cpp)
target_link_libraries(system.exe PRIVATE ReSolve)

# Create CUDA examples
if(RESOLVE_USE_CUDA)

Expand All @@ -40,6 +44,11 @@ if(RESOLVE_USE_CUDA)
#rand solver
add_executable(gmres_cusparse_rand.exe r_randGMRES_CUDA.cpp)
target_link_libraries(gmres_cusparse_rand.exe PRIVATE ReSolve)

# Build example with a configurable system solver
add_executable(system_cuda.exe r_SysSolverCuda.cpp)
target_link_libraries(system_cuda.exe PRIVATE ReSolve)

endif(RESOLVE_USE_CUDA)

# Create HIP examples
Expand All @@ -60,10 +69,17 @@ if(RESOLVE_USE_HIP)
# Rand GMRES test with rocsparse
add_executable(gmres_rocsparse_rand.exe r_randGMRES.cpp)
target_link_libraries(gmres_rocsparse_rand.exe PRIVATE ReSolve)
# Build example with a configurable system solver
add_executable(system_hip.exe r_SysSolverHip.cpp)
target_link_libraries(system_hip.exe PRIVATE ReSolve)

# Build example with a configurable system solver
add_executable(system_hip_fgmres.exe r_SysSolverHipRefine.cpp)
target_link_libraries(system_hip_fgmres.exe PRIVATE ReSolve)
endif(RESOLVE_USE_HIP)

# Install all examples in bin directory
set(installable_executables klu_klu.exe klu_klu_standalone.exe)
set(installable_executables klu_klu.exe klu_klu_standalone.exe system.exe)

if(RESOLVE_USE_CUDA)
set(installable_executables ${installable_executables} klu_glu.exe klu_rf.exe klu_rf_fgmres.exe klu_glu_values_update.exe gmres_cusparse_rand.exe)
Expand Down
16 changes: 7 additions & 9 deletions examples/r_KLU_GLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ int main(int argc, char *argv[])
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
if (i == 0) {
KLU->setupParameters(1, 0.1, false);
}
// if (i == 0) {
// KLU->setupParameters(1, 0.1, false);
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// }
int status;
if (i < 1) {
KLU->setup(A);
Expand All @@ -133,25 +133,23 @@ int main(int argc, char *argv[])
GLU->setup(A, L, U, P, Q);
status = GLU->solve(vec_rhs, vec_x);
std::cout<<"GLU solve status: "<<status<<std::endl;
// status = KLU->solve(vec_rhs, vec_x);
// std::cout<<"KLU solve status: "<<status<<std::endl;
} else {
//status = KLU->refactorize();
std::cout<<"Using CUSOLVER GLU"<<std::endl;
status = GLU->refactorize();
std::cout<<"CUSOLVER GLU refactorization status: "<<status<<std::endl;
status = GLU->solve(vec_rhs, vec_x);
std::cout<<"CUSOLVER GLU solve status: "<<status<<std::endl;
}
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);


// Estimate solution error
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
real_type bnorm = sqrt(vector_handler->dot(vec_r, vec_r, "cuda"));
matrix_handler->setValuesChanged(true, "cuda");
matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE,"csr", "cuda");

std::cout << "\t 2-Norm of the residual: "
<< std::scientific << std::setprecision(16)
<< sqrt(vector_handler->dot(vec_r, vec_r, "cuda")) << "\n";
<< sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))/bnorm << "\n";

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

Expand Down
6 changes: 3 additions & 3 deletions examples/r_KLU_GLU_matrix_values_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ int main(int argc, char *argv[])
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
if (i == 0) {
KLU->setupParameters(1, 0.1, false);
}
// if (i == 0) {
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// KLU->setupParameters(1, 0.1, false);
// }
int status;
if (i < 1){
KLU->setup(A);
Expand Down
6 changes: 3 additions & 3 deletions examples/r_KLU_KLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ int main(int argc, char *argv[])
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
if (i == 0) {
KLU->setupParameters(1, 0.1, false);
}
// if (i == 0) {
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// KLU->setupParameters(1, 0.1, false);
// }
int status;
if (i < 2){
KLU->setup(A);
Expand Down
2 changes: 1 addition & 1 deletion examples/r_KLU_KLU_standalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int main(int argc, char *argv[])
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);
// KLU->setupParameters(1, 0.1, false);
pelesh marked this conversation as resolved.
Show resolved Hide resolved
int status;
KLU->setup(A);
status = KLU->analyze();
Expand Down
6 changes: 3 additions & 3 deletions examples/r_KLU_rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ int main(int argc, char *argv[] )
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
if (i == 0) {
KLU->setupParameters(1, 0.1, false);
}
// if (i == 0) {
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// KLU->setupParameters(1, 0.1, false);
// }
int status;
if (i < 2){
KLU->setup(A);
Expand Down
6 changes: 3 additions & 3 deletions examples/r_KLU_rf_FGMRES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ int main(int argc, char *argv[])
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
if (i == 0) {
KLU->setupParameters(1, 0.1, false);
}
// if (i == 0) {
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// KLU->setupParameters(1, 0.1, false);
// }
int status;
real_type norm_b;
if (i < 2){
Expand Down
6 changes: 3 additions & 3 deletions examples/r_KLU_rf_FGMRES_reuse_factorization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ int main(int argc, char *argv[])
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
if (i == 0) {
KLU->setupParameters(1, 0.1, false);
}
// if (i == 0) {
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// KLU->setupParameters(1, 0.1, false);
// }
int status;
real_type norm_b;
if (i < 2){
Expand Down
28 changes: 14 additions & 14 deletions examples/r_KLU_rocSolverRf_FGMRES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ int main(int argc, char *argv[])
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
if (i == 0) {
KLU->setupParameters(1, 0.1, false);
}
// if (i == 0) {
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// KLU->setupParameters(1, 0.1, false);
// }
int status;
real_type norm_b;
if (i < 2){
Expand Down Expand Up @@ -175,17 +175,17 @@ int main(int argc, char *argv[])
<< rnrm/norm_b << "\n";

vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
if(!std::isnan(rnrm) && !std::isinf(rnrm)) {
FGMRES->solve(vec_rhs, vec_x);

std::cout << "FGMRES: init nrm: "
<< std::scientific << std::setprecision(16)
<< FGMRES->getInitResidualNorm()/norm_b
<< " final nrm: "
<< FGMRES->getFinalResidualNorm()/norm_b
<< " iter: " << FGMRES->getNumIter() << "\n";
}
}
if(!std::isnan(rnrm) && !std::isinf(rnrm)) {
FGMRES->solve(vec_rhs, vec_x);

std::cout << "FGMRES: init nrm: "
<< std::scientific << std::setprecision(16)
<< FGMRES->getInitResidualNorm()/norm_b
<< " final nrm: "
<< FGMRES->getFinalResidualNorm()/norm_b
<< " iter: " << FGMRES->getNumIter() << "\n";
}
}

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

Expand Down
15 changes: 7 additions & 8 deletions examples/r_KLU_rocsolverrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ int main(int argc, char *argv[] )
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
if (i == 0) {
KLU->setupParameters(1, 0.1, false);
}
// if (i == 0) {
// KLU->setupParameters(1, 0.1, false);
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// }
int status;
if (i < 2){
if (i < 2) {
KLU->setup(A);
status = KLU->analyze();
std::cout<<"KLU analysis status: "<<status<<std::endl;
Expand All @@ -134,7 +134,6 @@ int main(int argc, char *argv[] )
index_type* Q = KLU->getQOrdering();
vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
Rf->setup(A, L, U, P, Q, vec_rhs);
Rf->refactorize();
}
} else {
std::cout<<"Using rocsolver rf"<<std::endl;
Expand All @@ -143,15 +142,15 @@ int main(int argc, char *argv[] )
status = Rf->solve(vec_rhs, vec_x);
std::cout<<"rocsolver rf solve status: "<<status<<std::endl;
}
vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);

vec_r->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE);
real_type bnorm = sqrt(vector_handler->dot(vec_r, vec_r, "hip"));
matrix_handler->setValuesChanged(true, "hip");

matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE,"csr", "hip");

std::cout << "\t 2-Norm of the residual: "
<< std::scientific << std::setprecision(16)
<< sqrt(vector_handler->dot(vec_r, vec_r, "hip")) << "\n";
<< sqrt(vector_handler->dot(vec_r, vec_r, "hip"))/bnorm << "\n";

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

Expand Down
6 changes: 3 additions & 3 deletions examples/r_KLU_rocsolverrf_redo_factorization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ int main(int argc, char *argv[] )
}
std::cout<<"COO to CSR completed. Expanded NNZ: "<< A->getNnzExpanded()<<std::endl;
//Now call direct solver
if (i == 0) {
KLU->setupParameters(1, 0.1, false);
}
// if (i == 0) {
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// KLU->setupParameters(1, 0.1, false);
// }
int status;
if (i < 2){
KLU->setup(A);
Expand Down
Loading
Loading