17#include <Comm_Group.h>
19#include <communications.h>
20#include <Sortie_Nulle.h>
23#include <Synonyme_info.h>
24#include <petsc_for_kernel.h>
26#include <TRUST_Error.h>
27#include <Comm_Group_MPI.h>
30#include <FichierHDFPar.h>
31#include <EChaineJDD.h>
32#include <DeviceMemory.h>
41static Sortie std_err_(cerr);
43static Sortie std_out_(cout);
47static int journal_file_open_;
48static Nom journal_file_name_;
52static int verbose_level_ = 0;
53static int disable_stop_ = 0;
57static int cerr_to_journal_ = 0;
62 char* theValue = getenv(
"TRUST_MultipleFiles");
68 Cerr <<
"======================================================================================================" << finl;
69 Cerr <<
"Warning! Single file option is forced for " << filename <<
" above " <<
multiple_files <<
" MPI ranks." << finl;
70 Cerr <<
"for I/O performance reasons on cluster and inodes number limitation." << finl;
71 Cerr <<
"If you want to keep multiple files, add at the beginning of your data file to outpass the limitation:" << finl;
72 Cerr <<
"MultipleFiles " << ranks << finl;
73 Cerr <<
"=====================================================================================================" << finl;
176template<
typename _TYPE_>
180 assert_parallel<_TYPE_>(sz);
183 _TYPE_ *data = x.
addr();
184 _TYPE_ *tmp =
new _TYPE_[sz];
187 memcpy(data, tmp, sz *
sizeof(_TYPE_));
192template<
typename _TYPE_>
195template<
typename _TYPE_>
198template<
typename _TYPE_>
209 T data[2] = {arg1, arg2};
220 T data[3] = {arg1, arg2, arg3};
232 T data[4] = {arg1, arg2, arg3, arg4};
246 T data[2] = {arg1, arg2};
257 T data[3] = {arg1, arg2, arg3};
269 T data[4] = {arg1, arg2, arg3, arg4};
283 T data[2] = {arg1, arg2};
294 T data[3] = {arg1, arg2, arg3};
306 T data[4] = {arg1, arg2, arg3, arg4};
320 T data[5] = {arg1, arg2, arg3, arg4, arg5};
334 T data[5] = {arg1, arg2, arg3, arg4, arg5};
348 T data[5] = {arg1, arg2, arg3, arg4, arg5};
430 if (v >= std::numeric_limits<int>::max())
431 Process::exit(
"Value too big - above 32b and can not be converted to int!!");
432 return static_cast<int>(v);
457 Nom message=
"=========================================\nTRUST has caused an error and will stop.\nUnexpected error during TRUST calculation.";
471 Cerr << message << finl;
474 if (getenv(
"TRUST_USE_XDATA")!=
nullptr)
477 hier <<
"\n KEYWORDS\n";
479 hier <<
"\n SYNONYMS\n";
488 ficstop <<message<<finl;
520 MPI_Isend(buffer, 1, MPI_ENTIER, to_pe, tag, mpi_comm, &request);
523 int from_pe = (
me()==0?
nproc()-1:
me()-1);
524 MPI_Irecv(buffer, 1, MPI_ENTIER, from_pe, tag, mpi_comm, &request);
532 MPI_Test(&request,&ok,&status);
541 std_err_ <<
"!!! TRUST process number " <<
Process::me() <<
" exited unexpectedly ! See error message at the end of the file " << journal_file_name_ <<
" -> Aborting calculation..." << finl;
550 MPI_Initialized(&flag);
553 MPI_Finalized(&flag);
590 if (message_level <= verbose_level_ && verbose_level_ > 0)
592 if (journal_file_open_)
593 return journal_file_;
597 return journal_zero_;
604 PetscLogDouble memoire;
605 PetscMemoryGetCurrentUsage(&memoire);
611#include <sys/resource.h>
616 getrusage(RUSAGE_SELF, &usage);
618 long rss_kb = usage.ru_maxrss;
619 return static_cast<double>(rss_kb*1024);
636double heap_allocation()
639#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 33)
640 struct mallinfo2 info = mallinfo2();
642 struct mallinfo info = mallinfo();
644 return (
double)info.uordblks;
647static double heap_allocated_old=0;
655 memoire = ru_maxrss();
658 double heap_allocated = heap_allocation();
665 if (all_process)
Journal() << (int)(memoire/Mo) <<
" MBytes of RAM taken by the processor " <<
Process::me() << finl;
669 Cout << (int)(total_memoire/Mo) <<
" MBytes of RAM taken by the calculation (max on a rank: "<<(int)(max_memoire/Mo)<<
" MB)." << finl;
671 Cout <<
"[RAM] Allocated heap on master rank: " << (int)(heap_allocated/Mo) <<
" Mbytes";
672 double delta = heap_allocated - heap_allocated_old;
673 if (delta!=0 && heap_allocated_old>0) Cout <<
" (" << (delta>0 ?
"+" :
"") << (
long)delta <<
" bytes)";
675 heap_allocated_old = heap_allocated;
680 Cout << 0.1*(int)(10*allocated/Go) <<
" GBytes of maximal RAM allocated on a GPU (" << int(100 * allocated / total) <<
"%)" << finl;
686 std::ifstream meminfo(
"/proc/meminfo");
688 size_t sunreclaim_kb = 0;
689 size_t mem_available_kb = 0;
690 size_t mem_total_kb = 0;
691 while (std::getline(meminfo, line))
693 if (line.substr(0, 9) ==
"MemTotal:")
695 size_t pos = line.find_first_of(
"0123456789");
696 mem_total_kb = std::stoull(line.substr(pos));
698 if (line.substr(0, 13) ==
"MemAvailable:")
700 size_t pos = line.find_first_of(
"0123456789");
701 mem_available_kb = std::stoull(line.substr(pos));
703 if (line.substr(0, 11) ==
"SUnreclaim:")
705 size_t pos = line.find_first_of(
"0123456789");
706 sunreclaim_kb = std::stoull(line.substr(pos));
710 Process::Journal() <<
"[RAM] SUnreclaim: " << sunreclaim_kb/1024 <<
" MB MemAvailable: " << mem_available_kb/1024 <<
" MB MemTotal: " << mem_total_kb/1024 <<
" MB " << finl;
721void init_journal_file(
int verbose_level,
const char * file_name,
int append)
723 end_journal(verbose_level);
725 if (verbose_level > 0)
729 IOS_OPEN_MODE mode = ios::out;
732 if (!journal_file_.ouvrir(file_name, mode))
734 Cerr <<
"Fatal error in init_journal_file: cannot open journal file" << finl;
738 journal_file_open_ = 1;
739 journal_file_name_ = file_name;
742 verbose_level_ = verbose_level;
745void end_journal(
int verbose_level)
749 journal_file_.close();
750 journal_file_open_ = 0;
760 if (journal_file_open_ && cerr_to_journal_)
761 return journal_file_;
771 else if (verbose_level_)
772 return journal_file_;
774 return journal_zero_;
787 if (journal_file_open_ && cerr_to_journal_)
788 return journal_file_;
794 return journal_zero_;
804void set_Cerr_to_journal(
int flag)
806 cerr_to_journal_ = flag;
809int get_journal_level()
811 return verbose_level_;
814void change_journal_level(
int level)
816 verbose_level_ = level;
824int get_disable_stop()
826 return disable_stop_;
834void change_disable_stop(
int new_stop)
836 disable_stop_ = new_stop;
: Classe Comm_Group_MPI, derivee de la classe abstraite Comm_Group.
: Cette classe decrit un groupe de processeurs sur lesquels
int nproc() const
Renvoie le nombre de processeurs dans le groupe *this.
int rank() const
Renvoie le rang du processeur local dans le groupe *this.
virtual void abort() const =0
virtual void mp_collective_op(const double *x, double *resu, int n, Collective_Op op) const =0
virtual void barrier(int tag) const =0
static int file_cur_line_
class Nom Une chaine de caractere pour nommer les objets de TRUST
const std::string & getString() const
static const Nom & nom_du_cas()
Renvoie une reference constante vers le nom du cas.
static const int & get_nb_groups()
static void finalize()
Methode a appeler en fin d'execution, une fois qu'on est revenu dans le groupe_TRUST() et juste avant...
static const Comm_Group & get_user_defined_group()
Renvoie une reference au groupe sur defini par l'utilisateur.
static const Comm_Group & get_node_group()
Renvoie une reference au groupe sur les noeuds.
static bool has_user_defined_group()
static const Comm_Group & current_group()
renvoie une reference au groupe de processeurs actif courant
static const Comm_Group & groupe_TRUST()
Renvoie une reference au groupe de tous les processeurs TRUST.
static void mp_max_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
static double mp_min(double)
static int check_int_overflow(trustIdType)
static void mp_sum_for_each(T &arg1, T &arg2)
C++14 compatible mp_sum_for_each: combine multiple mp_sum calls into one collective operation Usage: ...
static double ram_processeur()
static trustIdType mppartial_sum(trustIdType i)
Calul de la somme partielle de i sur les processeurs 0 a me()-1 (renvoie 0 sur le processeur 0).
static int multiple_files
static double mp_max(double)
static void mp_sum_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
static int node_master()
renvoie 1 si on est sur le processeur maitre du noeud numa, 0 sinon.
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 void abort()
Routine de sortie de Trio-U sur une erreur abort().
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
static void mp_max_for_each(T &arg1, T &arg2)
C++14 compatible mp_max_for_each: combine multiple mp_max calls into one collective operation.
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 void mp_min_for_each(T &arg1, T &arg2)
C++14 compatible mp_min_for_each: combine multiple mp_min calls into one collective operation.
static int exception_sur_exit
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),...
static void mp_min_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
static bool is_sequential()
static bool mp_and(bool)
Calcule le 'et' logique de b sur tous les processeurs du groupe courant.
Cette classe est a la classe C++ ofstream ce que la classe Sortie est a la classe C++ ostream Elle re...
Classe derivee de Sortie qui ne sort les donnees nulle part (c'est une poubelle) Classe utilisee dans...
Classe de base des flux de sortie.
static Sortie & hierarchie(Sortie &)
Ecriture de toute la hierarchie du synonyme considere sur un flux de sortie.
Represents a an array of int/int64/double/... values.
_SIZE_ size_array() const
static Sortie & hierarchie(Sortie &)
Ecriture de toute la hierarchie du type considere sur un flix de sortie.
static size_t allocatedBytesOnDevice()
static size_t deviceMemGetInfo(bool)