TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Process.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Process_included
17#define Process_included
18
19#include <TRUST_Version.h> // so that it is accessible from everywhere in TRUST
20#include <TRUSTTabs_forward.h>
21#include <arch.h>
22
23#ifdef LATATOOLS
24#include <string>
25#include <stdlib.h>
26#include <stdexcept>
27#else
28#include <kokkos++.h>
29#endif
30
31class Objet_U;
32class Nom;
33class Sortie;
34
35int get_disable_stop();
36void change_disable_stop(int new_stop);
37
38/*! @brief Classe de base de TRUST (notamment Objet_U).
39 *
40 * Elle fournit quelques services de base
41 * accessibles de partout dans le code (ces services etaient historiquement
42 * des methodes non statiques, depuis que tous ces services sont statiques,
43 * cette classe n'a plus vraiment d'autre fonction que de ranger ces methodes
44 * quelque part)
45 *
46 * @sa Objet_U
47 */
48
50{
51public:
52 virtual ~Process() { }
53
54 // Simplified dummy API for lata_tools
55#ifdef LATATOOLS
56 static int me() { return 0; }
57 static int nproc() { return 1; }
58 static bool is_parallel() { return false; }
59 static void exit(int exit_code = -1) { throw std::invalid_argument("an error is occured"); }
60 static void exit(const std::string& s) { throw std::invalid_argument(std::string("an error is occured ")+s); }
61 static double mp_sum(double x) { return x; }
62 static float mp_sum(float x) { return x; }
63 static double mp_max(double x) { return x; }
64 static int mp_max(int x) { return x; }
65 static double mp_min(double x) { return x; }
66 static int mp_min(int x) { return x; }
67 static trustIdType mp_sum(int x) { return x; }
68 static trustIdType mp_sum(trustIdType x) { return x; }
69 template<typename _TYPE_>
70 static void mp_sum_for_each_item(TRUSTArray<_TYPE_>& x) { }
71 template<typename _TYPE_>
72 static void mp_max_for_each_item(TRUSTArray<_TYPE_>& x) { }
73 template<typename _TYPE_>
74 static void mp_min_for_each_item(TRUSTArray<_TYPE_>& x) { }
75#else
76 static int me(); /* mon rang dans le groupe courant */
77 static int nproc();
78 static bool is_parallel();
79 static void exit(int exit_code = -1);
80
81 //
82 // Reduction
83 //
84 static double mp_sum(double);
85 static float mp_sum(float);
86 static trustIdType mp_sum(trustIdType);
87 static double mp_max(double);
88 static double mp_min(double);
89 static int mp_max(int);
90 static int mp_min(int);
91#if INT_is_64_ == 2
92 // Careful, the sum of many 'int' on several procs, might return a 'long'!!
93 static trustIdType mp_sum(int v) { return mp_sum(static_cast<trustIdType>(v)); }
94 static trustIdType mp_max(trustIdType);
95 static trustIdType mp_min(trustIdType);
96#endif
97
98 // When computing percentages or ratios, useful:
99 static double mp_sum_as_double(int v) { return static_cast<double>(mp_sum(v)); }
100#if INT_is_64_ == 2
101 static double mp_sum_as_double(trustIdType v) { return static_cast<double>(mp_sum(v)); }
102#endif
103
104 // Summing for all procs before me:
105 static trustIdType mppartial_sum(trustIdType i);
106#if INT_is_64_ == 2
107 static trustIdType mppartial_sum(int i) { return mppartial_sum(static_cast<trustIdType>(i)); }
108#endif
109
110 // Reduction on several values (C++14 compatible - explicit overloads)
111 // mp_sum_for_each
112 template<typename T>
113 static void mp_sum_for_each(T& arg1, T& arg2);
114 template<typename T>
115 static void mp_sum_for_each(T& arg1, T& arg2, T& arg3);
116 template<typename T>
117 static void mp_sum_for_each(T& arg1, T& arg2, T& arg3, T& arg4);
118 template<typename T>
119 static void mp_sum_for_each(T& arg1, T& arg2, T& arg3, T& arg4, T& arg5);
120 // mp_max_for_each
121 template<typename T>
122 static void mp_max_for_each(T& arg1, T& arg2);
123 template<typename T>
124 static void mp_max_for_each(T& arg1, T& arg2, T& arg3);
125 template<typename T>
126 static void mp_max_for_each(T& arg1, T& arg2, T& arg3, T& arg4);
127 template<typename T>
128 static void mp_max_for_each(T& arg1, T& arg2, T& arg3, T& arg4, T& arg5);
129 // mp_min_for_each
130 template<typename T>
131 static void mp_min_for_each(T& arg1, T& arg2);
132 template<typename T>
133 static void mp_min_for_each(T& arg1, T& arg2, T& arg3);
134 template<typename T>
135 static void mp_min_for_each(T& arg1, T& arg2, T& arg3, T& arg4);
136 template<typename T>
137 static void mp_min_for_each(T& arg1, T& arg2, T& arg3, T& arg4, T& arg5);
138 // Reduction on values of a TRUSTArray
139 template<typename _TYPE_>
140 static void mp_sum_for_each_item(TRUSTArray<_TYPE_>& x, int n=-1);
141 template<typename _TYPE_>
142 static void mp_max_for_each_item(TRUSTArray<_TYPE_>& x, int n=-1);
143 template<typename _TYPE_>
144 static void mp_min_for_each_item(TRUSTArray<_TYPE_>& x, int n=-1);
145
146 static bool mp_and(bool);
147 static bool mp_or(bool);
148
149 static int check_int_overflow(trustIdType);
150
151 static int je_suis_maitre();
152 KOKKOS_INLINE_FUNCTION static void Kokkos_exit(const char*);
153 static int node_master();
154 static void exit(const Nom& message, int exit_code = -1);
155 static bool is_sequential(); // serial ?
156 static void barrier();
157 static void abort();
158
159 static Sortie& Journal(int message_level = 0);
160 static double ram_processeur();
161 static void imprimer_ram_totale(int all_process = 0);
162 //static void print_allocated_memory(std::string s); // To look for memory increase
164 static int multiple_files;
165 static bool force_single_file(const int ranks, const Nom& filename);
166#endif
167};
168
169/*! @brief Routine de sortie de TRUST dans une region Kokkos
170 *
171 */
172#ifndef LATATOOLS
173KOKKOS_INLINE_FUNCTION void Process::Kokkos_exit(const char* str)
174{
175#ifdef KOKKOS
176 // ToDo Kokkos: try to exit more properly on device...
177 Kokkos::abort(str);
178 //Kokkos::finalize();
179#else
180 Process::exit(str);
181#endif
182}
183#endif
184
185#endif /* Process_included */
186
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
Classe de base de TRUST (notamment Objet_U).
Definition Process.h:50
static void mp_max_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:196
static double mp_min(double)
Definition Process.cpp:386
static int check_int_overflow(trustIdType)
Definition Process.cpp:428
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: ...
Definition Process.cpp:207
static double ram_processeur()
Definition Process.cpp:601
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).
Definition Process.cpp:396
static KOKKOS_INLINE_FUNCTION void Kokkos_exit(const char *)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.h:173
static int multiple_files
Definition Process.h:164
static double mp_max(double)
Definition Process.cpp:376
static void mp_sum_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:193
static bool mp_or(bool)
Definition Process.cpp:418
static int node_master()
renvoie 1 si on est sur le processeur maitre du noeud numa, 0 sinon.
Definition Process.cpp:95
static bool is_parallel()
Definition Process.cpp:110
static Sortie & Journal(int message_level=0)
Renvoie un objet statique de type Sortie qui sert de journal d'evenements.
Definition Process.cpp:588
static void abort()
Routine de sortie de Trio-U sur une erreur abort().
Definition Process.cpp:570
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
Definition Process.cpp:104
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
Definition Process.cpp:146
virtual ~Process()
Definition Process.h:52
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.
Definition Process.cpp:244
static double mp_sum_as_double(int v)
Definition Process.h:99
static void imprimer_ram_totale(int all_process=0)
Definition Process.cpp:651
static void barrier()
Synchronise tous les processeurs du groupe courant (attend que tous les processeurs soient arrives a ...
Definition Process.cpp:136
static bool force_single_file(const int ranks, const Nom &filename)
Definition Process.cpp:60
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.
Definition Process.cpp:281
static int exception_sur_exit
Definition Process.h:163
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
static int je_suis_maitre()
renvoie 1 si on est sur le processeur maitre du groupe courant (c'est a dire me() == 0),...
Definition Process.cpp:86
static void mp_min_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:199
static bool is_sequential()
Definition Process.cpp:115
static bool mp_and(bool)
Calcule le 'et' logique de b sur tous les processeurs du groupe courant.
Definition Process.cpp:409
Classe de base des flux de sortie.
Definition Sortie.h:52