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>
40static Sortie std_err_(cerr);
42static Sortie std_out_(cout);
46static int journal_file_open_;
47static Nom journal_file_name_;
50static int verbose_level_ = 0;
51static int disable_stop_ = 0;
54static int cerr_to_journal_ = 0;
59 char* theValue = getenv(
"TRUST_MultipleFiles");
65 Cerr <<
"======================================================================================================" << finl;
66 Cerr <<
"Warning! Single file option is forced for " << filename <<
" above " <<
multiple_files <<
" MPI ranks." << finl;
67 Cerr <<
"for I/O performance reasons on cluster and inodes number limitation." << finl;
68 Cerr <<
"If you want to keep multiple files, add at the beginning of your data file to outpass the limitation:" << finl;
69 Cerr <<
"MultipleFiles " << ranks << finl;
70 Cerr <<
"=====================================================================================================" << finl;
177template<
typename _TYPE_>
181 assert_parallel<_TYPE_>(sz);
184 _TYPE_ *data = x.
addr();
185 _TYPE_ *tmp =
new _TYPE_[sz];
188 memcpy(data, tmp, sz *
sizeof(_TYPE_));
193template<
typename _TYPE_>
196template<
typename _TYPE_>
199template<
typename _TYPE_>
210 T data[2] = {arg1, arg2};
221 T data[3] = {arg1, arg2, arg3};
233 T data[4] = {arg1, arg2, arg3, arg4};
247 T data[2] = {arg1, arg2};
258 T data[3] = {arg1, arg2, arg3};
270 T data[4] = {arg1, arg2, arg3, arg4};
284 T data[2] = {arg1, arg2};
295 T data[3] = {arg1, arg2, arg3};
307 T data[4] = {arg1, arg2, arg3, arg4};
321 T data[5] = {arg1, arg2, arg3, arg4, arg5};
335 T data[5] = {arg1, arg2, arg3, arg4, arg5};
349 T data[5] = {arg1, arg2, arg3, arg4, arg5};
439 if (v >= std::numeric_limits<int>::max())
440 Process::exit(
"Value too big - above 32b and can not be converted to int!!");
441 return static_cast<int>(v);
468 Nom message=
"=========================================\nTRUST has caused an error and will stop.\nUnexpected error during TRUST calculation.";
482 Cerr << message << finl;
490 ficstop <<message<<finl;
522 MPI_Isend(buffer, 1, MPI_ENTIER, to_pe, tag, mpi_comm, &request);
525 int from_pe = (
me()==0?
nproc()-1:
me()-1);
526 MPI_Irecv(buffer, 1, MPI_ENTIER, from_pe, tag, mpi_comm, &request);
534 MPI_Test(&request,&ok,&status);
543 std_err_ <<
"!!! TRUST process number " <<
Process::me() <<
" exited unexpectedly ! See error message at the end of the file " << journal_file_name_ <<
" -> Aborting calculation..." << finl;
552 MPI_Initialized(&flag);
555 MPI_Finalized(&flag);
594 if (message_level <= verbose_level_ && verbose_level_ > 0)
596 if (journal_file_open_)
597 return journal_file_;
601 return journal_zero_;
608 PetscLogDouble memoire;
609 PetscMemoryGetCurrentUsage(&memoire);
615#include <sys/resource.h>
620 getrusage(RUSAGE_SELF, &usage);
622 long rss_kb = usage.ru_maxrss;
623 return static_cast<double>(rss_kb*1024);
640double heap_allocation()
643#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 33)
644 struct mallinfo2 info = mallinfo2();
646 struct mallinfo info = mallinfo();
648 return (
double)info.uordblks;
651static double heap_allocated_old=0;
659 memoire = ru_maxrss();
662 double heap_allocated = heap_allocation();
669 if (all_process)
Journal() << (int)(memoire/Mo) <<
" MBytes of RAM taken by the processor " <<
Process::me() << finl;
673 Cout << (int)(total_memoire/Mo) <<
" MBytes of RAM taken by the calculation (max on a rank: "<<(int)(max_memoire/Mo)<<
" MB)." << finl;
675 Cout <<
"[RAM] Allocated heap on master rank: " << (int)(heap_allocated/Mo) <<
" Mbytes";
676 double delta = heap_allocated - heap_allocated_old;
677 if (delta!=0 && heap_allocated_old>0) Cout <<
" (" << (delta>0 ?
"+" :
"") << (
long)delta <<
" bytes)";
679 heap_allocated_old = heap_allocated;
684 Cout << 0.1*(int)(10*allocated/Go) <<
" GBytes of maximal RAM allocated on a GPU (" << int(100 * allocated / total) <<
"%)" << finl;
690 std::ifstream meminfo(
"/proc/meminfo");
692 size_t sunreclaim_kb = 0;
693 size_t mem_available_kb = 0;
694 size_t mem_total_kb = 0;
695 while (std::getline(meminfo, line))
697 if (line.substr(0, 9) ==
"MemTotal:")
699 size_t pos = line.find_first_of(
"0123456789");
700 mem_total_kb = std::stoull(line.substr(pos));
702 if (line.substr(0, 13) ==
"MemAvailable:")
704 size_t pos = line.find_first_of(
"0123456789");
705 mem_available_kb = std::stoull(line.substr(pos));
707 if (line.substr(0, 11) ==
"SUnreclaim:")
709 size_t pos = line.find_first_of(
"0123456789");
710 sunreclaim_kb = std::stoull(line.substr(pos));
714 Process::Journal() <<
"[RAM] SUnreclaim: " << sunreclaim_kb/1024 <<
" MB MemAvailable: " << mem_available_kb/1024 <<
" MB MemTotal: " << mem_total_kb/1024 <<
" MB " << finl;
725void init_journal_file(
int verbose_level,
const char * file_name,
int append)
727 end_journal(verbose_level);
729 if (verbose_level > 0)
733 IOS_OPEN_MODE mode = ios::out;
736 if (!journal_file_.ouvrir(file_name, mode))
738 Cerr <<
"Fatal error in init_journal_file: cannot open journal file" << finl;
742 journal_file_open_ = 1;
743 journal_file_name_ = file_name;
746 verbose_level_ = verbose_level;
749void end_journal(
int verbose_level)
753 journal_file_.close();
754 journal_file_open_ = 0;
765 if (journal_file_open_ && cerr_to_journal_)
766 return journal_file_;
776 else if (verbose_level_)
777 return journal_file_;
779 return journal_zero_;
793 if (journal_file_open_ && cerr_to_journal_)
794 return journal_file_;
800 return journal_zero_;
811void set_Cerr_to_journal(
int flag)
813 cerr_to_journal_ = flag;
816int get_journal_level()
818 return verbose_level_;
821void change_journal_level(
int level)
823 verbose_level_ = level;
831int get_disable_stop()
833 return disable_stop_;
841void change_disable_stop(
int new_stop)
843 disable_stop_ = new_stop;
: Class Comm_Group_MPI, derived from the abstract class Comm_Group.
: This class describes a group of processors on which
int nproc() const
Returns the number of processors in the group *this.
int rank() const
Returns the rank of the local processor in the group *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: a character string for naming TRUST objects.
const std::string & getString() const
static const Nom & nom_du_cas()
Returns a constant reference to the case name. This method is static.
static const int & get_nb_groups()
static void finalize()
Method to call at the end of execution, once back in groupe_TRUST() and just before destroying the ma...
static const Comm_Group & get_user_defined_group()
Returns a reference to the user-defined group.
static const Comm_Group & get_node_group()
Returns a reference to the node-level communicator group.
static bool has_user_defined_group()
static const Comm_Group & current_group()
Returns a reference to the current active processor group.
static const Comm_Group & groupe_TRUST()
Returns a reference to the group containing all TRUST processors.
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)
Computes the partial sum of x over processors 0 to me()-1 (returns 0 on processor 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()
Returns 1 if on the NUMA node master processor, 0 otherwise.
static bool is_parallel()
static Sortie & Journal(int message_level=0)
Returns a static Sortie object used as an event journal.
static void abort()
Abort routine for TRUST on a fatal error.
static int nproc()
Returns the number of processors in the current group. See Comm_Group::nproc() and PE_Groups::current...
static double mp_sum(double)
Computes the sum of x over all processors in the current group.
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()
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 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()
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.
static void mp_min_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
static bool is_sequential()
static bool mp_and(bool)
Computes the logical AND of b across all processors in the current group.
SFichier is to the C++ ofstream class what Sortie is to the C++ ostream class.
Derived class of Sortie that sends data nowhere (it is a sink). Used in Journal() when logging is dis...
Base class for output streams.
Represents a an array of int/int64/double/... values.
_SIZE_ size_array() const
static size_t allocatedBytesOnDevice()
static size_t deviceMemGetInfo(bool)