From 126b16aa0f1fe5a9ac11a4c62b232eb78da0c74b Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Sat, 21 Oct 2023 16:16:06 -0400 Subject: [PATCH] Fix I/O in examples. --- examples/r_KLU_GLU.cpp | 5 ++- examples/r_KLU_GLU_matrix_values_update.cpp | 5 ++- examples/r_KLU_KLU.cpp | 9 ++--- examples/r_KLU_KLU_standalone.cpp | 7 ++-- examples/r_KLU_rf.cpp | 5 ++- examples/r_KLU_rf_FGMRES.cpp | 12 +++++- .../r_KLU_rf_FGMRES_reuse_factorization.cpp | 38 ++++++++++++++----- runResolve | 6 +-- 8 files changed, 62 insertions(+), 25 deletions(-) diff --git a/examples/r_KLU_GLU.cpp b/examples/r_KLU_GLU.cpp index e0831976..e2cbfde4 100644 --- a/examples/r_KLU_GLU.cpp +++ b/examples/r_KLU_GLU.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -148,7 +149,9 @@ int main(int argc, char *argv[]) matrix_handler->setValuesChanged(true, "cuda"); matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE,"csr", "cuda"); - printf("\t 2-Norm of the residual: %16.16e\n", sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))); + std::cout << "\t 2-Norm of the residual: " + << std::scientific << std::setprecision(16) + << sqrt(vector_handler->dot(vec_r, vec_r, "cuda")) << "\n"; } // for (int i = 0; i < numSystems; ++i) diff --git a/examples/r_KLU_GLU_matrix_values_update.cpp b/examples/r_KLU_GLU_matrix_values_update.cpp index e6e09673..7d1bb141 100644 --- a/examples/r_KLU_GLU_matrix_values_update.cpp +++ b/examples/r_KLU_GLU_matrix_values_update.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -158,7 +159,9 @@ int main(int argc, char *argv[]) matrix_handler->setValuesChanged(true, "cuda"); matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE,"csr", "cuda"); - printf("\t 2-Norm of the residual: %16.16e\n", sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))); + std::cout << "\t 2-Norm of the residual: " + << std::scientific << std::setprecision(16) + << sqrt(vector_handler->dot(vec_r, vec_r, "cuda")) << "\n"; } diff --git a/examples/r_KLU_KLU.cpp b/examples/r_KLU_KLU.cpp index 19c9fc33..8b0ea59a 100644 --- a/examples/r_KLU_KLU.cpp +++ b/examples/r_KLU_KLU.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -138,12 +139,10 @@ int main(int argc, char *argv[]) matrix_handler->setValuesChanged(true, "cpu"); matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE, "csr", "cpu"); - real_type* test = vec_r->getData("cpu"); - (void) test; // TODO: Do we need `test` variable in this example? - - printf("\t 2-Norm of the residual: %16.16e\n", sqrt(vector_handler->dot(vec_r, vec_r, "cpu"))); - + std::cout << "\t 2-Norm of the residual: " + << std::scientific << std::setprecision(16) + << sqrt(vector_handler->dot(vec_r, vec_r, "cpu")) << "\n"; } //now DELETE diff --git a/examples/r_KLU_KLU_standalone.cpp b/examples/r_KLU_KLU_standalone.cpp index 9d658b6e..77e5b97a 100644 --- a/examples/r_KLU_KLU_standalone.cpp +++ b/examples/r_KLU_KLU_standalone.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -100,10 +101,10 @@ int main(int argc, char *argv[]) matrix_handler->setValuesChanged(true, "cpu"); matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE, "csr", "cpu"); - real_type* test = vec_r->getData("cpu"); - (void) test; // TODO: Do we need `test` variable in this example? - printf("\t 2-Norm of the residual: %16.16e\n", sqrt(vector_handler->dot(vec_r, vec_r, "cpu"))); + std::cout << "\t 2-Norm of the residual: " + << std::scientific << std::setprecision(16) + << sqrt(vector_handler->dot(vec_r, vec_r, "cpu")) << "\n"; diff --git a/examples/r_KLU_rf.cpp b/examples/r_KLU_rf.cpp index 5dce2dfe..01fa0f3c 100644 --- a/examples/r_KLU_rf.cpp +++ b/examples/r_KLU_rf.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -162,7 +163,9 @@ int main(int argc, char *argv[] ) matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE,"csr", "cuda"); - printf("\t 2-Norm of the residual: %16.16e\n", sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))); + std::cout << "\t 2-Norm of the residual: " + << std::scientific << std::setprecision(16) + << sqrt(vector_handler->dot(vec_r, vec_r, "cuda")) << "\n"; } // for (int i = 0; i < numSystems; ++i) diff --git a/examples/r_KLU_rf_FGMRES.cpp b/examples/r_KLU_rf_FGMRES.cpp index 2e43f9c3..ee674869 100644 --- a/examples/r_KLU_rf_FGMRES.cpp +++ b/examples/r_KLU_rf_FGMRES.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -171,12 +172,19 @@ int main(int argc, char *argv[]) matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE,"csr", "cuda"); - printf("\t 2-Norm of the residual (before IR): %16.16e\n", sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))/norm_b); + std::cout << "\t 2-Norm of the residual (before IR): " + << std::scientific << std::setprecision(16) + << sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))/norm_b << "\n"; vec_rhs->update(rhs, "cpu", "cuda"); FGMRES->solve(vec_rhs, vec_x); - printf("FGMRES: init nrm: %16.16e final nrm: %16.16e iter: %d \n", FGMRES->getInitResidualNorm()/norm_b, FGMRES->getFinalResidualNorm()/norm_b, FGMRES->getNumIter()); + 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) diff --git a/examples/r_KLU_rf_FGMRES_reuse_factorization.cpp b/examples/r_KLU_rf_FGMRES_reuse_factorization.cpp index 2317680c..6a520a7a 100644 --- a/examples/r_KLU_rf_FGMRES_reuse_factorization.cpp +++ b/examples/r_KLU_rf_FGMRES_reuse_factorization.cpp @@ -1,5 +1,7 @@ #include #include +#include + #include #include #include @@ -138,7 +140,9 @@ int main(int argc, char *argv[]) norm_b = sqrt(norm_b); matrix_handler->setValuesChanged(true, "cuda"); matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE,"csr", "cuda"); - printf("\t 2-Norm of the residual : %16.16e\n", sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))/norm_b); + std::cout << "\t 2-Norm of the residual : " + << std::scientific << std::setprecision(16) + << sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))/norm_b << "\n"; if (i == 1) { ReSolve::matrix::Csc* L_csc = (ReSolve::matrix::Csc*) KLU->getLFactor(); ReSolve::matrix::Csc* U_csc = (ReSolve::matrix::Csc*) KLU->getUFactor(); @@ -147,7 +151,9 @@ int main(int argc, char *argv[]) matrix_handler->csc2csr(L_csc,L, "cuda"); matrix_handler->csc2csr(U_csc,U, "cuda"); - if (L == nullptr) {printf("ERROR");} + if (L == nullptr) { + std::cout << "ERROR\n"; + } index_type* P = KLU->getPOrdering(); index_type* Q = KLU->getQOrdering(); Rf->setup(A, L, U, P, Q); @@ -163,14 +169,17 @@ int main(int argc, char *argv[]) if ((i % 2 == 0)) { status = Rf->refactorize(); - std::cout<<"CUSOLVER RF, using REAL refactorization, refactorization status: "<update(rhs, "cpu", "cuda"); 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("cuda"); real_type norm_x = vector_handler->dot(vec_x, vec_x, "cuda"); - printf("Norm of x(before solve): %16.16e \n", sqrt(norm_x)); + std::cout << "Norm of x (before solve): " + << std::scientific << std::setprecision(16) + << sqrt(norm_x) << "\n"; std::cout<<"CUSOLVER RF solve status: "<update(rhs, "cpu", "cuda"); @@ -183,15 +192,26 @@ int main(int argc, char *argv[]) matrix_handler->matvec(A, vec_x, vec_r, &ONE, &MINUSONE,"csr", "cuda"); - printf("\t 2-Norm of the residual (before IR): %16.16e\n", sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))/norm_b); - printf("\t 2-Norm of the RIGHT HAND SIDE: %16.16e\n", norm_b); + std::cout << "\t 2-Norm of the residual (before IR): " + << std::scientific << std::setprecision(16) + << sqrt(vector_handler->dot(vec_r, vec_r, "cuda"))/norm_b << "\n"; + std::cout << "\t 2-Norm of the RIGHT HAND SIDE: " + << std::scientific << std::setprecision(16) + << norm_b << "\n"; vec_rhs->update(rhs, "cpu", "cuda"); FGMRES->solve(vec_rhs, vec_x); - printf("FGMRES: init nrm: %16.16e final nrm: %16.16e iter: %d \n", FGMRES->getInitResidualNorm()/norm_b, FGMRES->getFinalResidualNorm()/norm_b, FGMRES->getNumIter()); + std::cout << "FGMRES: init nrm: " + << std::scientific << std::setprecision(16) + << FGMRES->getInitResidualNorm()/norm_b + << " final nrm: " + << FGMRES->getFinalResidualNorm()/norm_b + << " iter: " << FGMRES->getNumIter() << "\n"; norm_x = vector_handler->dot(vec_x, vec_x, "cuda"); - printf("Norm of x (after IR): %16.16e \n", sqrt(norm_x)); + std::cout << "Norm of x (after IR): " + << std::scientific << std::setprecision(16) + << sqrt(norm_x) << "\n"; } diff --git a/runResolve b/runResolve index 0a8e5dbf..2d5c67ca 100755 --- a/runResolve +++ b/runResolve @@ -13,9 +13,9 @@ foo=" ${foo} ${i} ${i}" done -matfile="/gpfs/wolf/csc359/scratch/peles/testcases/ACTIVSg10k_AC/matrix_ACTIVSg10k_AC_" +matfile="$HOME/testcases/ACTIVSg10k_AC/matrix_ACTIVSg10k_AC_" -rhsfile="/gpfs/wolf/csc359/scratch/peles/testcases/ACTIVSg10k_AC/rhs_ACTIVSg10k_AC_" +rhsfile="$HOME/testcases/ACTIVSg10k_AC/rhs_ACTIVSg10k_AC_" -./resolve/klu_rf_fgmres.exe $matfile $rhsfile 10 $foo +./$1 $matfile $rhsfile 10 $foo