20#include <Solv_Petsc_GPU.h>
22#include <rocm-core/rocm_version.h>
25#include <MD_Vector_composite.h>
61 if ((Motcle)solver_!=
"GCP")
63 Cerr << solver_ <<
" not supported yet for AMG !" << finl;
71 else if (motcle==
"RTOL") is >> rtol_;
72 else if (motcle==
"ATOL") is >> atol_;
73 else if (motcle==
"ST") is >> st_;
74 else if (motcle==
"IMPR") impr_ =
true;
77 else if (motcle==
"SEUIL")
Process::exit(
"Use atol 'absolute tolerance' instead of seuil.");
82 Cerr << motcle <<
" is not an option of AMG solver." << finl;
87 if (atol_<0 && rtol_<0)
Process::exit(
"atol or rtol should be defined in AMG solver.");
91void Solv_AMG::create_block_amg(
int n,
Nom precond)
93 if (getenv(
"TRUST_AMG")!=
nullptr) precond = getenv(
"TRUST_AMG");
97 chaine_lue_+=rtol_>0 ? Nom(rtol_,
" -ksp_rtol %e") :
"";
98 chaine_lue_+=atol_>0 ? Nom(atol_,
" -ksp_atol %e") :
"";
101-pc_fieldsplit_type additive";
107 Cerr <<
"If Gamg setup crashes during MatProductSymbolic_SeqAIJCUSPARSE_SeqAIJCUSPARSE, it is related to not enough RAM device." << finl;
108 Cerr <<
"Use more GPUs, or try slower options: -fieldsplit_P0_pc_gamg_agg_nsmooths 0 -fieldsplit_P1_pc_gamg_agg_nsmooths 0" << finl;
109 chaine_lue_+=
" -info :pc -fieldsplit_P0_ksp_type preonly \
110-fieldsplit_P0_pc_type gamg \
111-fieldsplit_P0_pc_gamg_threshold 0.01 \
112-fieldsplit_P0_pc_gamg_square_graph 1 \
113-fieldsplit_P1_ksp_type preonly \
114-fieldsplit_P1_pc_type gamg \
115-fieldsplit_P1_pc_gamg_threshold 0.01 \
116-fieldsplit_P1_pc_gamg_square_graph 1";
120-fieldsplit_Pa_ksp_type preonly \
121-fieldsplit_Pa_pc_type gamg \
122-fieldsplit_Pa_pc_gamg_threshold 0.01 \
123-fieldsplit_Pa_pc_gamg_square_graph 1";
128 chaine_lue_+=
" -mat_type aijkokkos -vec_type kokkos";
132 else if (precond==
"boomeramg")
135-fieldsplit_P0_pc_type hypre \
136-fieldsplit_P0_pc_hypre_type boomeramg \
137-fieldsplit_P0_pc_hypre_boomeramg_strong_threshold 0.1 \
138-fieldsplit_P0_pc_hypre_boomeramg_print_statistics 1 \
139-fieldsplit_P1_ksp_type preonly \
140-fieldsplit_P1_pc_type hypre \
141-fieldsplit_P1_pc_hypre_type boomeramg \
142-fieldsplit_P1_pc_hypre_boomeramg_strong_threshold 0.1 \
143-fieldsplit_P1_pc_hypre_boomeramg_print_statistics 1";
147-fieldsplit_Pa_pc_type hypre \
148-fieldsplit_Pa_pc_hypre_type boomeramg \
149-fieldsplit_Pa_pc_hypre_boomeramg_strong_threshold 0.1 \
150-fieldsplit_Pa_pc_hypre_boomeramg_print_statistics 1";
154 if (n==2)
chaine_lue_+=
" -fieldsplit_P0_pc_mg_galerkin_mat_product_algorithm hypre";
155 if (n==2)
chaine_lue_+=
" -fieldsplit_P1_pc_mg_galerkin_mat_product_algorithm hypre";
156 if (n==3)
chaine_lue_+=
" -fieldsplit_Pa_pc_mg_galerkin_mat_product_algorithm hypre";
159 else if (precond==
"amgx")
161 Cerr <<
"Warning! PETSc with AmgX preconditioner was not tested yet for nnz>2^31 !" << finl;
163-fieldsplit_P0_pc_type amgx \
164-fieldsplit_P0_pc_amgx_strength_threshold 0.1 \
165-fieldsplit_P0_pc_amgx_verbose 1 \
166-fieldsplit_P0_pc_amgx_print_grid_stats 1 \
167-fieldsplit_P1_ksp_type preonly \
168-fieldsplit_P1_pc_type amgx \
169-fieldsplit_P1_pc_amgx_strength_threshold 0.1 \
170-fieldsplit_P1_pc_amgx_verbose 1 \
171-fieldsplit_P1_pc_amgx_print_grid_stats 1";
175-fieldsplit_Pa_pc_type amgx \
176-fieldsplit_Pa_pc_amgx_strength_threshold 0.5 \
177-fieldsplit_Pa_pc_amgx_verbose 1 \
178-fieldsplit_Pa_pc_amgx_print_grid_stats 1";
186Nom boomeramg(
double st)
188 Nom chaine(
" { precond boomeramg { }");
191 chaine +=
" cli { -pc_hypre_boomeramg_strong_threshold";
192 chaine +=
Nom(st,
"%e");
197void Solv_AMG::create_amg()
201#if defined(TRUST_USE_CUDA)
202 library_ =
"petsc_gpu";
206#if defined(MPIX_CUDA_AWARE_SUPPORT)
212 if (st_>=0)
chaine_lue_ += Nom(st_,
" p:strength_threshold %e");
216#elif defined(TRUST_USE_ROCM)
217 library_ =
"petsc_gpu";
218 const char* value = std::getenv(
"ROCM_ARCH");
219 if (value !=
nullptr && std::string(value) ==
"gfx1100")
221 if (st_>=0)
Process::exit(
"st option not supported yet in Solv_AMG");
233 chaine_lue_ += rtol_>0 ? Nom(rtol_,
" rtol %e") : Nom(atol_,
" atol %e");
250 Cerr <<
"Detecting " << nb_blocks <<
"x" << nb_blocks <<
" blocks into the matrix. Creating a specific block preconditioning:" << finl;
252 create_block_amg(nb_blocks,
"gamg");
254 create_block_amg(nb_blocks,
"boomeramg");
255 else if (library_==
"amgx")
257 library_ =
"petsc_gpu";
258 create_block_amg(nb_blocks,
"amgx");
261 Cerr <<
"====================================================================" << finl;
262 Cerr <<
"Creating AMG solver: " << library_ <<
" " <<
chaine_lue_ << finl;
263 Cerr <<
"====================================================================" << finl;
265 Nom nom_solveur(
"Solv_");
266 nom_solveur+=library_;
267 solveur_.typer(nom_solveur);
268 solveur_.
nommer(
"solveur_pression");
269 if (library_==
"amgx")
270 ref_cast(
Solv_AMGX, solveur_.valeur()).create_solver(entree);
271 else if (library_==
"petsc")
272 ref_cast(
Solv_Petsc, solveur_.valeur()).create_solver(entree);
273 else if (library_==
"petsc_gpu")
274 ref_cast(
Solv_Petsc_GPU, solveur_.valeur()).create_solver(entree);
280 statistics().end_count(STD_COUNTERS::system_solver,-1,0);
281 int res = solveur_.resoudre_systeme(mat, b, x);
282 statistics().begin_count(STD_COUNTERS::system_solver,statistics().get_last_opened_counter_level()+1);
Une entree dont la source est une chaine de caracteres.
Class defining operators and methods for all reading operation in an input flow (file,...
Metadata for a distributed composite vector.
const MD_Vector_base & valeur() const
Classe Matrice_Base Classe de base de la hierarchie des matrices.
class Nom Une chaine de caractere pour nommer les objets de TRUST
virtual void nommer(const Nom &)
Donne un nom a l'Objet_U Methode virtuelle a surcharger.
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
static bool is_parallel()
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
AMD solver wrapper to switch to the more robust/performant AMG preconditioner on CPU/GPU Nvidia/GPU A...
virtual int resoudre_systeme(const Matrice_Base &mat, const DoubleVect &b, DoubleVect &x) override
void set_save_matrix(int flag)
void set_read_matrix(bool flag)
Classe de base des flux de sortie.
virtual const MD_Vector & get_md_vector() const