diff --git a/resolve/LinSolverIterativeRandFGMRES.cpp b/resolve/LinSolverIterativeRandFGMRES.cpp index 6b7b3b1e..641deb26 100644 --- a/resolve/LinSolverIterativeRandFGMRES.cpp +++ b/resolve/LinSolverIterativeRandFGMRES.cpp @@ -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; @@ -93,7 +93,7 @@ namespace ReSolve maxit_= maxit; restart_ = restart; conv_cond_ = conv_cond; - flexible_ = 1; + flexible_ = true; d_V_ = nullptr; d_Z_ = nullptr; @@ -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 diff --git a/resolve/LinSolverIterativeRandFGMRES.hpp b/resolve/LinSolverIterativeRandFGMRES.hpp index 62601cb0..41252825 100644 --- a/resolve/LinSolverIterativeRandFGMRES.hpp +++ b/resolve/LinSolverIterativeRandFGMRES.hpp @@ -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