Skip to content

Commit

Permalink
Coding style fixes and minor cleanup in LinSolverIterativeRandFGMRES.
Browse files Browse the repository at this point in the history
  • Loading branch information
pelesh committed Dec 12, 2023
1 parent f3a2caa commit 15ebaa7
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 82 deletions.
5 changes: 2 additions & 3 deletions resolve/LinSolverIterativeRandFGMRES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace ReSolve
maxit_= 100; //default
restart_ = 10;
conv_cond_ = 0;//default
flexible_ = 1;
flexible_ = true;

d_V_ = nullptr;
d_Z_ = nullptr;
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace ReSolve
maxit_= maxit;
restart_ = restart;
conv_cond_ = conv_cond;
flexible_ = 1;
flexible_ = true;

d_V_ = nullptr;
d_Z_ = nullptr;
Expand Down Expand Up @@ -503,7 +503,6 @@ namespace ReSolve
void LinSolverIterativeRandFGMRES::precV(vector_type* rhs, vector_type* x)
{
LU_solver_->solve(rhs, x);
// x->update(rhs->getData(memory::DEVICE), memory::DEVICE, memory::DEVICE);
}

} // namespace ReSolve
162 changes: 83 additions & 79 deletions resolve/LinSolverIterativeRandFGMRES.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,90 +6,94 @@
#include "GramSchmidt.hpp"
#include "RandSketchingManager.hpp"

namespace ReSolve
namespace ReSolve
{

/**
* @brief Randomized (F)GMRES
*
* @note MatrixHandler and VectorHandler objects are inherited from
* LinSolver base class.
*
*/
class LinSolverIterativeRandFGMRES : public LinSolverIterative
{
using vector_type = vector::Vector;
private:
using vector_type = vector::Vector;

public:

enum SketchingMethod { cs = 0, // count sketch
fwht = 1}; // fast Walsh-Hadamard transform

LinSolverIterativeRandFGMRES(std::string memspace = "cuda");

LinSolverIterativeRandFGMRES( MatrixHandler* matrix_handler,
VectorHandler* vector_handler,
SketchingMethod rand_method,
GramSchmidt* gs,
std::string memspace = "cuda");

LinSolverIterativeRandFGMRES(index_type restart,
real_type tol,
index_type maxit,
index_type conv_cond,
MatrixHandler* matrix_handler,
VectorHandler* vector_handler,
SketchingMethod rand_method,
GramSchmidt* gs,
std::string memspace = "cuda");
~LinSolverIterativeRandFGMRES();

int solve(vector_type* rhs, vector_type* x);
int setup(matrix::Sparse* A);
int resetMatrix(matrix::Sparse* new_A);
int setupPreconditioner(std::string name, LinSolverDirect* LU_solver);

real_type getTol();
index_type getMaxit();
index_type getRestart();
index_type getConvCond();
bool getFlexible();
std::string getRandSketchingMethod();
index_type getKrand();

void setTol(real_type new_tol);
void setMaxit(index_type new_maxit);
void setRestart(index_type new_restart);
void setConvCond(index_type new_conv_cond);
void setFlexible(bool new_flexible);
void getRandSketchingMethod(std::string rand_method);
enum SketchingMethod { cs = 0, // count sketch
fwht = 1}; // fast Walsh-Hadamard transform

LinSolverIterativeRandFGMRES(std::string memspace = "cuda");

LinSolverIterativeRandFGMRES(MatrixHandler* matrix_handler,
VectorHandler* vector_handler,
SketchingMethod rand_method,
GramSchmidt* gs,
std::string memspace = "cuda");

LinSolverIterativeRandFGMRES(index_type restart,
real_type tol,
index_type maxit,
index_type conv_cond,
MatrixHandler* matrix_handler,
VectorHandler* vector_handler,
SketchingMethod rand_method,
GramSchmidt* gs,
std::string memspace = "cuda");

~LinSolverIterativeRandFGMRES();

int solve(vector_type* rhs, vector_type* x);
int setup(matrix::Sparse* A);
int resetMatrix(matrix::Sparse* new_A);
int setupPreconditioner(std::string name, LinSolverDirect* LU_solver);

real_type getTol();
index_type getMaxit();
index_type getRestart();
index_type getConvCond();
bool getFlexible();
// std::string getRandSketchingMethod();
index_type getKrand();

void setTol(real_type new_tol);
void setMaxit(index_type new_maxit);
void setRestart(index_type new_restart);
void setConvCond(index_type new_conv_cond);
void setFlexible(bool new_flexible);
// void setRandSketchingMethod(std::string rand_method);

private:
//remember matrix handler and vector handler are inherited.

memory::MemorySpace memspace_;

real_type tol_;
index_type maxit_;
index_type restart_;
std::string orth_option_;
index_type conv_cond_;
bool flexible_{1}; // if can be run as "normal" GMRES if needed, set flexible_ to 0. Default is 1 of course.

vector_type* d_V_{nullptr};
vector_type* d_Z_{nullptr};
// for performing Gram-Schmidt
vector_type* d_S_{nullptr};

real_type* h_H_{nullptr};
real_type* h_c_{nullptr};
real_type* h_s_{nullptr};
real_type* h_rs_{nullptr};
real_type* d_aux_{nullptr};


GramSchmidt* GS_;
void precV(vector_type* rhs, vector_type* x); //multiply the vector by preconditioner
LinSolverDirect* LU_solver_;
index_type n_;// for simplicity
real_type one_over_k_{1.0};

index_type k_rand_{0}; // size of sketch space, we need to know it so we can allocate S!
MemoryHandler mem_; ///< Device memory manager object
RandSketchingManager* rand_manager_;
SketchingMethod rand_method_;
memory::MemorySpace memspace_;

real_type tol_;
index_type maxit_;
index_type restart_;
std::string orth_option_;
index_type conv_cond_;
bool flexible_{true}; ///< if can be run as "normal" GMRES if needed, set flexible_ to `false`. Default is `true`, of course.

vector_type* d_V_{nullptr};
vector_type* d_Z_{nullptr};
// for performing Gram-Schmidt
vector_type* d_S_{nullptr};

real_type* h_H_{nullptr};
real_type* h_c_{nullptr};
real_type* h_s_{nullptr};
real_type* h_rs_{nullptr};
real_type* d_aux_{nullptr};

GramSchmidt* GS_;
void precV(vector_type* rhs, vector_type* x); ///< multiply the vector by preconditioner
LinSolverDirect* LU_solver_;
index_type n_;
real_type one_over_k_{1.0};

index_type k_rand_{0}; ///< size of sketch space. We need to know it so we can allocate S!
MemoryHandler mem_; ///< Device memory manager object
RandSketchingManager* rand_manager_{nullptr};
SketchingMethod rand_method_;
};
}
} // namespace ReSolve

0 comments on commit 15ebaa7

Please sign in to comment.