15#include <Solv_Optimal.h>
17#include <LecFicDistribueBin.h>
18#include <LecFicDiffuse.h>
19#include <Matrice_Bloc.h>
20#include <Matrice_Morse_Sym.h>
22#include <petsc_for_kernel.h>
24#include <MD_Vector_tools.h>
25#include <Perf_counters.h>
66void test_un_solveur(
SolveurSys& solveur,
const Matrice_Base& matrice,
const DoubleVect& secmem, DoubleVect& solution,
int nmax, ArrOfDouble& temps,
double seuil_verification=DMAXFLOAT)
68 DoubleVect solution_ref(solution);
69 int n=temps.size_array();
70 statistics().create_custom_counter(
"Custom solver",1);
71 for (
int i=0; i<n; i++)
73 solution=solution_ref;
76 statistics().begin_count(
"Custom solver",statistics().get_last_opened_counter_level()+1);
78 t_0 = statistics().get_total_time(
"Custom solver");
79 Cout<<
"------------------------------------"<<finl;
80 Cout<<
"Try " << i <<
" of solver " << solveur <<finl;
82 solveur.
nommer(
"test_solver");
85 t = statistics().get_time_since_last_open(
"Custom solver");
86 statistics().end_count(
"Custom solver");
88 DoubleVect test(secmem);
92 double norme=mp_norme_vect(test);
93 double time_resol = t-t_0;
94 Cout<<
"CPU= " <<time_resol<<
" s , ||Ax -b||= " << norme << finl;
98 if (norme>seuil_verification)
100 Cerr<<
"residue calculated greater than the threshold value indicated ("<<seuil_verification<<
")"<<finl;
101 Cerr<<
" one will not use the solver "<<solveur<<finl;
106int test_solveur(
SolveurSys& solveur,
const Matrice_Base& matrice ,
const DoubleVect& secmem , DoubleVect& solution ,
int nmax, ArrOfDouble& temps,
Entree& list_solveur,
double seuil_verification=DMAXFLOAT)
108 DoubleVect solution_ref(solution);
109 int numero=0,numero_best=-1;
110 double best_time=1e36;
111 Motcle motsolveur(
"solveur"),motlu;
112 list_solveur >> motlu;
113 int dernier=temps.size_array()-1;
114 while (list_solveur.
good())
116 if (motlu!=motsolveur)
118 Cerr<<
" One expected "<<motsolveur <<
" and not "<<motlu<<finl;
123 list_solveur>>newsolveur;
124 solution=solution_ref;
125 test_un_solveur(newsolveur, matrice, secmem ,solution, nmax, temps, seuil_verification);
126 if (temps[dernier]<best_time)
129 best_time=temps[dernier];
136 Cerr<<
" None of the tested solvers give the expected residue" <<finl;
137 Cerr<<
" does the same solver must be kept ? "<<finl;
146void generate_defaut(
const Matrice_Base& matrice,
const double seuil,
Sortie& sortie,
int limpr=0)
149 if (limpr==0) impr=
" ";
150 if (limpr==-1) impr=
" quiet ";
155 sortie <<
" solveur gmres { diag seuil "<<seuil <<
" "<<impr<<
"}"<<finl;
157 sortie <<
" solveur petsc bicgstab { precond diag { } seuil "<<seuil <<
" "<<impr<<
"}"<<finl;
164 sortie <<
" solveur gcp { precond ssor { omega 1.6 } seuil "<<seuil <<
" "<<impr<<
"}"<<finl;
166 sortie <<
" solveur petsc gcp { precond ssor { omega 1.6 } seuil "<<seuil <<
" "<<impr<<
"}"<<finl;
168 sortie <<
" solveur petsc cholesky { impr }"<< finl;
172 sortie <<
" solveur petsc bicgstab { precond block_jacobi_icc { level 1 } seuil "<<seuil <<
" "<<impr<<
"}"<<finl;
174 sortie <<
" solveur petsc gcp { precond block_jacobi_icc { level 1 } seuil "<<seuil <<
" "<<impr<<
"}"<<finl;
185 DoubleVect secmem,solution;
186 Nom fichier_secmem(
"Secmem.sa");
187 Nom fichier_solution(
"Solution.sa");
188 Nom fichier_matrice(
"Matrice.sa");
190 bool pas_de_solution_init=
false;
193 double seuil_verification=DMAXFLOAT;
197 Param param((*this).que_suis_je());
198 param.
ajouter(
"fichier_secmem",&fichier_secmem);
199 param.
ajouter(
"fichier_matrice",&fichier_matrice);
200 param.
ajouter(
"fichier_solution",&fichier_solution);
201 param.
ajouter(
"nb_test",&nb_test);
203 param.
ajouter(
"solveur",&solveur);
204 param.
ajouter(
"fichier_solveur",&fichier_solveur);
205 param.
ajouter(
"genere_fichier_solveur",&seuil_list);
206 param.
ajouter(
"seuil_verification",&seuil_verification);
207 param.
ajouter_flag(
"pas_de_solution_initiale",&pas_de_solution_init);
217 entree.
ouvrir(fichier_matrice);
219 Cout<<
" size of system "<<matrice.valeur( ).nb_colonnes()<<finl;
225 entree.
ouvrir(fichier_secmem);
227 Cout<<
" size of system "<<secmem.
size_totale()<<finl;
231 if (pas_de_solution_init)
240 entree.
ouvrir(fichier_solution);
243 Cout<<
" size of system "<<solution.
size_totale()<<finl;
249 if (fichier_solveur==
Nom())
250 fichier_solveur=
"list_solveur";
253 SFichier list_solveur(fichier_solveur);
254 generate_defaut(matrice,seuil_list,list_solveur,limpr_);
260 ArrOfDouble temps(nb_test);
261 if (fichier_solveur==
Nom())
262 test_un_solveur(solveur, matrice , secmem , solution , -10, temps,seuil_verification);
266 int numero_best=test_solveur(solveur, matrice , secmem , solution , -10, temps,list_solveur,seuil_verification);
267 Cout <<
"------------------------------------------------"<<finl;
268 Cout <<
"Best solver : number "<<numero_best<<
" "<<solveur<<finl;
269 Cout <<
"Best CPU time = "<<temps[0]<<finl;
270 Cout <<
"------------------------------------------------"<<finl;
275static int numero_solv_optimal=0;
276Solv_Optimal::Solv_Optimal():n_resol_(0),n_reinit_(0)
278 freq_recalc_ = (int)(pow(2.0,(
double)((
sizeof(
int)*8)-1))-1);
280 fichier_solveur_=
"solveurs_";
281 fichier_solveur_+=
Nom(numero_solv_optimal);
282 numero_solv_optimal++;
285Solv_Optimal::~Solv_Optimal()
298 Param param((*this).que_suis_je());
300 param.ajouter_flag(
"impr",&impr);
301 param.ajouter_flag(
"quiet",&quiet);
306 param.lire_avec_accolades_depuis(is);
332 generate_defaut(matrice,
seuil_,list_solveur,
limpr());
349 ArrOfDouble temps(nb_ite);
350 statistics().end_count(STD_COUNTERS::system_solver,0,0);
351 int numero_best=test_solveur(
le_solveur_, matrice , secmem , solution , nmax, temps,list_solveur,
seuil_);
352 statistics().begin_count(STD_COUNTERS::system_solver,statistics().get_last_opened_counter_level()+1);
353 Cout <<
"------------------------------------------------"<<finl;
354 Cout <<
"Best solver : number "<<numero_best<<
" "<<
le_solveur_<<finl;
355 Cout <<
"Best CPU time = "<<temps[0]<<finl;
356 Cout <<
"------------------------------------------------"<<finl;
369 return le_solveur_->resoudre_systeme( matrice, secmem, solution);
374 return le_solveur_->resoudre_systeme( matrice, secmem, solution, nmax );
Class defining operators and methods for all reading operation in an input flow (file,...
void set_bin(bool bin) override
Changes the file write mode.
Base class for "interpreter" objects.
This class implements the operators and virtual methods of the EFichier class as follows: The file to...
This class implements the operators and virtual methods of the EFichier class as follows: there are a...
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in) override
Opens the file with the given mode and prot parameters. These parameters are the parameters of the st...
Matrice_Base class - Base class of the matrix hierarchy.
virtual DoubleVect & ajouter_multvect(const DoubleVect &x, DoubleVect &r) const
Matrix-vector multiply-accumulate operation (saxpy).
Matrice_Morse_Sym class - Represents a sparse symmetric matrix M stored in Morse format.
Matrice class - Generic class in the matrix hierarchy.
A character string (Nom) in uppercase.
class Nom: a character string for naming TRUST objects.
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Helper class to factorize the readOn method of Objet_U classes.
void ajouter_flag(const char *keyword, const bool *value)
Register a boolean flag whose mere presence switches it to true.
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
int lire_avec_accolades_depuis(Entree &is)
Parse the parameter block { ... } from is.
static double mp_max(double)
static int nproc()
Returns the number of processors in the current group. See Comm_Group::nproc() and PE_Groups::current...
static void imprimer_ram_totale(int all_process=0)
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
SFichier is to the C++ ofstream class what Sortie is to the C++ ostream class.
int resoudre_systeme(const Matrice_Base &, const DoubleVect &, DoubleVect &) override
bool fichier_solveur_non_recree_
void prepare_resol(const Matrice_Base &matrice, const DoubleVect &secmem, DoubleVect &solution, int nmax=100)
Key method of Solv_Optimal: at the first iteration,.
class SolveurSys A SolveurSys represents any class
int resoudre_systeme(const Matrice_Base &matrice, const DoubleVect &secmem, DoubleVect &solution)
void nommer(const Nom &nom) override
Base class for output streams.
_SIZE_ size_totale() const
virtual void set_md_vector(const MD_Vector &)
virtual const MD_Vector & get_md_vector() const
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")
Entree & interpreter(Entree &) override