17#include <LecFicDiffuse_JDD.h>
18#include <TClearable.h>
19#include <instancie_appel.h>
21#include <Comm_Group_MPI.h>
25#include <Perf_counters.h>
26#include <communications.h>
27#include <petsc_for_kernel.h>
29#include <petscdevice.h>
32#include <Baltik_Version.h>
33#include <info_atelier.h>
36#include <catch_and_trace.h>
43static bool TRUST_LIBRARY_MODE =
false;
46void TRUST_set_library_mode(
bool b)
48 TRUST_LIBRARY_MODE = b;
51void TRUST_global_finalize()
53 if (!TRUST_LIBRARY_MODE)
return;
57 PetscBool isInitialized;
58 PetscInitialized(&isInitialized);
59 if (isInitialized==PETSC_TRUE)
61 PetscPopErrorHandler();
66 if (Kokkos::is_initialized())
70mon_main::mon_main(
int verbose_level,
bool journal_master,
Nom log_directory,
bool apply_verification,
bool disable_stop)
72 verbose_level_ = verbose_level;
73 journal_master_ = journal_master;
74 log_directory_ = log_directory;
77 init_journal_file(verbose_level, 0 , 0 );
78 trio_began_mpi_=
false;
79 disable_stop_=disable_stop;
80 change_disable_stop(disable_stop);
83static int init_petsc(
int argc,
char **argv,
bool with_mpi,
bool& trio_began_mpi_)
86 PetscBool isInitialized;
87 PetscInitialized(&isInitialized);
91 static char help[] =
"TRUST may solve linear systems with Petsc library.\n\n" ;
94#ifdef MPI_INIT_NEEDS_MPIRUN
96 MPI_Initialized(&flag);
100 PetscInitialize(&argc, &argv, (
char*)0, help);
103 PetscInitialize(&argc, &argv, (
char*)0, help);
107 PetscDeviceCreate(PETSC_DEVICE_DEFAULT(), PETSC_DECIDE, &device);
108 PetscDeviceView(device, PETSC_VIEWER_STDERR_WORLD);
119 Cerr <<
"Error on chdir into mon_main.cpp. Contact TRUST support." << finl;
124 PetscPushErrorHandler(PetscAbortErrorHandler, PETSC_NULLPTR);
127 PetscPopSignalHandler();
130 Cerr <<
"Enabling error handlers catching SIGFPE and SIGABORT and giving a trace of where the fault happened." << finl;
137 MPI_Initialized(&flag);
140 MPI_Init(&argc,&argv);
141 trio_began_mpi_=
true;
149static int init_parallel_mpi(OWN_PTR(
Comm_Group) & groupe_trio)
152 groupe_trio.typer(
"Comm_Group_MPI");
161static void instantiate_node_mpi(OWN_PTR(
Comm_Group) & ngrp, OWN_PTR(
Comm_Group) & mgrp,
int with_mpi)
165 ngrp.typer(
"Comm_Group_MPI");
166 mgrp.typer(
"Comm_Group_MPI");
170 ngrp.typer(
"Comm_Group_NoParallel");
171 mgrp.typer(
"Comm_Group_NoParallel");
175static void init_node_mpi(OWN_PTR(
Comm_Group) & ngrp)
180 mpi_on_node.init_comm_on_numa_node();
184static void init_node_masters(OWN_PTR(
Comm_Group) & master)
189 mm.init_comm_on_node_master();
200 bool init_kokkos_before_mpi = (getenv(
"KOKKOS_AFTER_MPI") ==
nullptr);
202 if (init_kokkos_before_mpi && !Kokkos::is_initialized())
206 Kokkos::initialize(argc2, argv);
208 Nom arguments_info =
"";
209 arguments_info +=
"Kokkos initialized!\n";
211 bool must_mpi_initialize =
true;
214 if (init_petsc(argc, argv, with_mpi, trio_began_mpi_))
216 must_mpi_initialize =
false;
217 arguments_info +=
"Petsc initialization succeeded.\n";
221 arguments_info +=
"Petsc initialization failed (not compiled ?). Not fatal...\n";
226 arguments_info +=
"Petsc initialization skipped (-petsc=0).\n";
229 Comm_Group_MPI::set_must_mpi_initialize(must_mpi_initialize);
232 if (must_mpi_initialize) abort();
239 if (!init_parallel_mpi(groupe_trio_))
241 Cerr <<
"MPI initialization failed (not compiled ?). Fatal." << finl;
246 groupe_trio_.typer(
"Comm_Group_NoParallel");
250 arguments_info +=
"Parallel engine initialized : ";
252 arguments_info +=
" with ";
254 arguments_info +=
" processors\n";
257 Cerr << arguments_info;
261 instantiate_node_mpi(node_group_, node_master_, with_mpi);
263 if (!init_kokkos_before_mpi && !Kokkos::is_initialized())
267 Kokkos::initialize(argc2, argv);
269 Cerr <<
"Kokkos initialized after MPI !" << finl;
274 Kokkos::print_configuration(std::cerr,
true);
276 Cerr <<
"You can run --kokkos-help option." << finl;
308 if (!TRUST_LIBRARY_MODE)
311 PetscBool isInitialized;
312 PetscInitialized(&isInitialized);
313 if (isInitialized==PETSC_TRUE)
315 PetscPopErrorHandler();
326 if (!TRUST_LIBRARY_MODE && trio_began_mpi_)
330 MPI_Initialized(&flag);
333 MPI_Finalized(&flag);
339 if (!TRUST_LIBRARY_MODE && Kokkos::is_initialized())
350 Nom tmp = nom_du_cas;
351 envoyer(tmp, 0, -1, 0);
352 recevoir(tmp, 0, -1, 0);
362 Nom mkdir_command(
"mkdir -p ");
363 mkdir_command += log_directory_;
364 if(system(mkdir_command))
366 Cerr <<
"Error while creating directory: " << log_directory_ <<
"\n";
371 Nom filename = log_directory_ + nom_du_cas;
386 if (verbose_level_ < 0)
394 init_journal_file(verbose_level_,filename, 0 );
405 Nom nomfic( nom_du_cas );
410 ficstop <<
"Running..."<<finl;
418 Cerr<<
"Chargement des modules:"<<finl;
419#include <instancie_appel_c.h>
420 Cerr<<
"Fin chargement des modules "<<finl;
425 init_node_mpi(node_group_);
430 init_node_masters(node_master_);
434 Cout<<
" * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << finl;
435 Cout<<
" * _________ _______ _______ _________ * " << finl;
436 Cout<<
" * \\__ __/ ( ____ ) |\\ /| ( ____ \\ \\__ __/ * " << finl;
437 Cout<<
" * ) ( | ( )| | ) ( | | ( \\/ ) ( * " << finl;
438 Cout<<
" * | | | (____)| | | | | | (_____ | | * " << finl;
439 Cout<<
" * | | | __) | | | | (_____ ) | | * " << finl;
440 Cout<<
" * | | | (\\ ( | | | | ) | | | * " << finl;
441 Cout<<
" * | | | ) \\ \\__ | (___) | /\\____) | | | * " << finl;
442 Cout<<
" * )_( |/ \\__/ (_______) \\_______) )_( * " << finl;
443 Cout<<
" * * " << finl;
444 Cout<<
" * version : " << TRUST_VERSION <<
" * " << finl;
445 Cout<<
" * * " << finl;
447 Cout<<
" * Using " << BALTIK_NAME <<
" version : " << BALTIK_VERSION <<
" *" << finl;
449 Cout<<
" * * " << finl;
450 Cout<<
" * CEA - DES * " << finl;
451 Cout<<
" * * " << finl;
452 Cout<<
" * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << finl;
462 Cerr<<
"Debut de l'execution " << finl;
464 Nom nomentree = nom_du_cas;
477 Cerr <<
"MAIN: Checking data file for matching { and }" << finl;
480 interprete_principal_.interpreter_bloc(verifie_entree,
485 Cerr <<
"MAIN: Reading and executing data file" << finl;
489 interprete_principal_.interpreter_bloc(lit_entree,
495 Cerr <<
"MAIN: End of data file" << finl;
498 statistics().print_TU_files(
"Post-resolution statistics");
500 double temps = statistics().get_computation_time();
502 Cout <<
"--------------------------------------------" << finl;
503 Cout <<
"clock: Total execution: " << temps <<
" s" << finl;
507 ficstop <<
"Finished correctly"<<finl;
516 end_journal(verbose_level_);
518 interprete_principal_.vide();
523 groupe_trio_.detach();
524 node_group_.detach();
: Classe Comm_Group_MPI, derivee de la classe abstraite Comm_Group.
: Cette classe decrit un groupe de processeurs sur lesquels
static void set_check_enabled(int flag)
void init_group_trio(int nproc, int rank)
Initialise le groupe_TRUST().
Cette classe implemente les operateurs et les methodes virtuelles de la classe EFichier de la facon s...
static bool apply_verif
! whether obsolete keywords should be checked or not. True by default.
void set_check_types(bool flag) override
appelle get_entree_master().
class Nom Une chaine de caractere pour nommer les objets de TRUST
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
static const Nom & nom_du_cas()
Renvoie une reference constante vers le nom du cas.
static Nom & get_set_nom_du_cas()
Renvoie une reference non constante vers le nom du cas (pour pouvoir le modifier).
static void initialize_node_master(const Comm_Group &ngrp)
Methode a appeler apres l'initialisation de trio_u_world et de node_group et l'initialisation des com...
static void finalize()
Methode a appeler en fin d'execution, une fois qu'on est revenu dans le groupe_TRUST() et juste avant...
static void initialize(const Comm_Group &groupe_trio_u)
Methode a appeler au debut de l'execution (MAIN.
static void initialize_node(const Comm_Group &ngrp)
Methode a appeler apres l'initialisation de trio_u_world et l'initialisation des compteurs statistiqu...
static const Comm_Group & get_user_defined_group()
Renvoie une reference au groupe sur defini par l'utilisateur.
static bool has_user_defined_group()
static const Comm_Group & current_group()
renvoie une reference au groupe de processeurs actif courant
static bool is_parallel()
static Sortie & Journal(int message_level=0)
Renvoie un objet statique de type Sortie qui sert de journal d'evenements.
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
static void imprimer_ram_totale(int all_process=0)
static void barrier()
Synchronise tous les processeurs du groupe courant (attend que tous les processeurs soient arrives a ...
static bool force_single_file(const int ranks, const Nom &filename)
static int me()
renvoie mon rang dans le groupe de communication courant.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
static int je_suis_maitre()
renvoie 1 si on est sur le processeur maitre du groupe courant (c'est a dire me() == 0),...
Cette classe est a la classe C++ ofstream ce que la classe Sortie est a la classe C++ ostream Elle re...
void dowork(const Nom &nom_du_cas)
mon_main(int verbose_level=9, bool journal_master=false, Nom log_directory="", bool apply_verification=true, bool disable_stop=false)
void init_parallel(const int argc, char **argv, bool with_mpi, bool check_enabled=false, bool with_petsc=true)