Skip to content

Commit

Permalink
Fix I/O in examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
pelesh committed Oct 21, 2023
1 parent 3037513 commit 126b16a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 25 deletions.
5 changes: 4 additions & 1 deletion examples/r_KLU_GLU.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string>
#include <iostream>
#include <iomanip>

#include <resolve/matrix/Coo.hpp>
#include <resolve/matrix/Csr.hpp>
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion examples/r_KLU_GLU_matrix_values_update.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string>
#include <iostream>
#include <iomanip>

#include <resolve/vector/Vector.hpp>
#include <resolve/matrix/io.hpp>
Expand Down Expand Up @@ -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";


}
Expand Down
9 changes: 4 additions & 5 deletions examples/r_KLU_KLU.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>

#include <resolve/matrix/Coo.hpp>
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions examples/r_KLU_KLU_standalone.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>

#include <resolve/matrix/Coo.hpp>
Expand Down Expand Up @@ -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";



Expand Down
5 changes: 4 additions & 1 deletion examples/r_KLU_rf.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string>
#include <iostream>
#include <iomanip>

#include <resolve/matrix/Coo.hpp>
#include <resolve/matrix/Csr.hpp>
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 10 additions & 2 deletions examples/r_KLU_rf_FGMRES.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string>
#include <iostream>
#include <iomanip>

#include <resolve/matrix/Coo.hpp>
#include <resolve/matrix/Csr.hpp>
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 29 additions & 9 deletions examples/r_KLU_rf_FGMRES_reuse_factorization.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <string>
#include <iostream>
#include <iomanip>

#include <resolve/GramSchmidt.hpp>
#include <resolve/matrix/Coo.hpp>
#include <resolve/matrix/Csr.hpp>
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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: "<<status<<std::endl;
std::cout << "CUSOLVER RF, using REAL refactorization, refactorization status: "
<< status << std::endl;
vec_rhs->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: "<<status<<std::endl;

vec_rhs->update(rhs, "cpu", "cuda");
Expand All @@ -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";
}


Expand Down
6 changes: 3 additions & 3 deletions runResolve
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 126b16a

Please sign in to comment.