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())
348 Nom tmp = nom_du_cas;
349 envoyer(tmp, 0, -1, 0);
350 recevoir(tmp, 0, -1, 0);
360 Nom mkdir_command(
"mkdir -p ");
361 mkdir_command += log_directory_;
362 if(system(mkdir_command))
364 Cerr <<
"Error while creating directory: " << log_directory_ <<
"\n";
369 Nom filename = log_directory_ + nom_du_cas;
384 if (verbose_level_ < 0)
392 init_journal_file(verbose_level_,filename, 0 );
403 Nom nomfic( nom_du_cas );
408 ficstop <<
"Running..."<<finl;
416 Cerr<<
"Loading modules:"<<finl;
417#include <instancie_appel_c.h>
418 Cerr<<
"Finished loading modules "<<finl;
423 init_node_mpi(node_group_);
428 init_node_masters(node_master_);
432 Cout<<
" * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << finl;
433 Cout<<
" * _________ _______ _______ _________ * " << finl;
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<<
" * version : " << TRUST_VERSION <<
" * " << finl;
443 Cout<<
" * * " << finl;
445 Cout<<
" * Using " << BALTIK_NAME <<
" version : " << BALTIK_VERSION <<
" *" << finl;
447 Cout<<
" * * " << finl;
448 Cout<<
" * CEA - DES * " << finl;
449 Cout<<
" * * " << finl;
450 Cout<<
" * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << finl;
460 Cerr<<
"Beginning execution" << finl;
462 Nom nomentree = nom_du_cas;
475 Cerr <<
"MAIN: Checking data file for matching { and }" << finl;
478 interprete_principal_.interpreter_bloc(verifie_entree,
483 Cerr <<
"MAIN: Reading and executing data file" << finl;
487 interprete_principal_.interpreter_bloc(lit_entree,
493 Cerr <<
"MAIN: End of data file" << finl;
496 statistics().print_TU_files(
"Post-resolution statistics");
498 double temps = statistics().get_computation_time();
500 Cout <<
"--------------------------------------------" << finl;
501 Cout <<
"clock: Total execution: " << temps <<
" s" << finl;
505 ficstop <<
"Finished correctly"<<finl;
514 end_journal(verbose_level_);
516 interprete_principal_.vide();
521 groupe_trio_.detach();
522 node_group_.detach();
: Class Comm_Group_MPI, derived from the abstract class Comm_Group.
: This class describes a group of processors on which
static void set_check_enabled(int flag)
void init_group_trio(int nproc, int rank)
Initializes groupe_TRUST().
This class implements the operators and virtual methods of the EFichier class as follows: The file to...
static bool apply_verif
! whether obsolete keywords should be checked or not. True by default.
void set_check_types(bool flag) override
Calls get_entree_master().
class Nom: a character string for naming TRUST objects.
const Nom & que_suis_je() const
Returns the string identifying the class.
static const Nom & nom_du_cas()
Returns a constant reference to the case name. This method is static.
static Nom & get_set_nom_du_cas()
Returns a non-constant reference to the case name (to allow modification). This method is static.
static void initialize_node_master(const Comm_Group &ngrp)
Method to call after the initialization of trio_u_world, node_group, and TRUST's statistical counters...
static void finalize()
Method to call at the end of execution, once back in groupe_TRUST() and just before destroying the ma...
static void initialize(const Comm_Group &groupe_trio_u)
Method to call at the beginning of execution (MAIN.cpp). Initializes current_group() with groupe_trio...
static void initialize_node(const Comm_Group &ngrp)
Method to call after the initialization of trio_u_world and TRUST's statistical counters.
static const Comm_Group & get_user_defined_group()
Returns a reference to the user-defined group.
static bool has_user_defined_group()
static const Comm_Group & current_group()
Returns a reference to the current active processor group.
static bool is_parallel()
static Sortie & Journal(int message_level=0)
Returns a static Sortie object used as an event journal.
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 barrier()
Synchronizes all processors in the current group (waits until all processors have reached the barrier...
static bool force_single_file(const int ranks, const Nom &filename)
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
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.
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)