TrioCFD 1.9.9_beta
TrioCFD documentation
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 Base class of TRUST (in particular Objet_U).
39 *
40 * It provides a few basic services accessible from anywhere in the code.
41 * These services were historically non-static methods; since all of them are now static,
42 * this class has no other purpose than to group those methods.
43 *
44 * @sa Objet_U
45 */
46
48{
49public:
50 virtual ~Process() { }
51
52 // Simplified dummy API for lata_tools
53#ifdef LATATOOLS
54 static int me() { return 0; }
55 static int nproc() { return 1; }
56 static bool is_parallel() { return false; }
57 static void exit(int exit_code = -1) { throw std::invalid_argument("an error is occured"); }
58 static void exit(const std::string& s) { throw std::invalid_argument(std::string("an error is occured ")+s); }
59 static double mp_sum(double x) { return x; }
60 static float mp_sum(float x) { return x; }
61 static double mp_max(double x) { return x; }
62 static int mp_max(int x) { return x; }
63 static double mp_min(double x) { return x; }
64 static int mp_min(int x) { return x; }
65 static trustIdType mp_sum(int x) { return x; }
66 static trustIdType mp_sum(trustIdType x) { return x; }
67 template<typename _TYPE_>
68 static void mp_sum_for_each_item(TRUSTArray<_TYPE_>& x) { }
69 template<typename _TYPE_>
70 static void mp_max_for_each_item(TRUSTArray<_TYPE_>& x) { }
71 template<typename _TYPE_>
72 static void mp_min_for_each_item(TRUSTArray<_TYPE_>& x) { }
73#else
74 static int me(); /* my rank in the current group */
75 static int nproc();
76 static bool is_parallel();
77 static void exit(int exit_code = -1);
78
79 //
80 // Reduction
81 //
82 static double mp_sum(double);
83 static float mp_sum(float);
84 static trustIdType mp_sum(trustIdType);
85 static double mp_max(double);
86 static double mp_min(double);
87 static int mp_max(int);
88 static int mp_min(int);
89#if INT_is_64_ == 2
90 // Careful, the sum of many 'int' on several procs, might return a 'long'!!
91 static trustIdType mp_sum(int v) { return mp_sum(static_cast<trustIdType>(v)); }
92 static trustIdType mp_max(trustIdType);
93 static trustIdType mp_min(trustIdType);
94#endif
95
96 // When computing percentages or ratios, useful:
97 static double mp_sum_as_double(int v) { return static_cast<double>(mp_sum(v)); }
98#if INT_is_64_ == 2
99 static double mp_sum_as_double(trustIdType v) { return static_cast<double>(mp_sum(v)); }
100#endif
101
102 // Summing for all procs before me:
103 static trustIdType mppartial_sum(trustIdType i);
104#if INT_is_64_ == 2
105 static trustIdType mppartial_sum(int i) { return mppartial_sum(static_cast<trustIdType>(i)); }
106#endif
107
108 // Reduction on several values (C++14 compatible - explicit overloads)
109 // mp_sum_for_each
110 template<typename T>
111 static void mp_sum_for_each(T& arg1, T& arg2);
112 template<typename T>
113 static void mp_sum_for_each(T& arg1, T& arg2, T& arg3);
114 template<typename T>
115 static void mp_sum_for_each(T& arg1, T& arg2, T& arg3, T& arg4);
116 template<typename T>
117 static void mp_sum_for_each(T& arg1, T& arg2, T& arg3, T& arg4, T& arg5);
118 // mp_max_for_each
119 template<typename T>
120 static void mp_max_for_each(T& arg1, T& arg2);
121 template<typename T>
122 static void mp_max_for_each(T& arg1, T& arg2, T& arg3);
123 template<typename T>
124 static void mp_max_for_each(T& arg1, T& arg2, T& arg3, T& arg4);
125 template<typename T>
126 static void mp_max_for_each(T& arg1, T& arg2, T& arg3, T& arg4, T& arg5);
127 // mp_min_for_each
128 template<typename T>
129 static void mp_min_for_each(T& arg1, T& arg2);
130 template<typename T>
131 static void mp_min_for_each(T& arg1, T& arg2, T& arg3);
132 template<typename T>
133 static void mp_min_for_each(T& arg1, T& arg2, T& arg3, T& arg4);
134 template<typename T>
135 static void mp_min_for_each(T& arg1, T& arg2, T& arg3, T& arg4, T& arg5);
136 // Reduction on values of a TRUSTArray
137 template<typename _TYPE_>
138 static void mp_sum_for_each_item(TRUSTArray<_TYPE_>& x, int n=-1);
139 template<typename _TYPE_>
140 static void mp_max_for_each_item(TRUSTArray<_TYPE_>& x, int n=-1);
141 template<typename _TYPE_>
142 static void mp_min_for_each_item(TRUSTArray<_TYPE_>& x, int n=-1);
143
144 static bool mp_and(bool);
145 static bool mp_or(bool);
146
147 static int check_int_overflow(trustIdType);
148
149 static int je_suis_maitre();
150 KOKKOS_INLINE_FUNCTION static void Kokkos_exit(const char*);
151 static int node_master();
152 static void exit(const Nom& message, int exit_code = -1);
153 static bool is_sequential(); // serial ?
154 static void barrier();
155 static void abort();
156
157 static Sortie& Journal(int message_level = 0);
158 static double ram_processeur();
159 static void imprimer_ram_totale(int all_process = 0);
160 //static void print_allocated_memory(std::string s); // To look for memory increase
162 static int multiple_files;
163 static bool force_single_file(const int ranks, const Nom& filename);
164#endif
165};
166
167/*! @brief Exit routine for TRUST within a Kokkos region.
168 *
169 * @param str Error message to display.
170 */
171#ifndef LATATOOLS
172KOKKOS_INLINE_FUNCTION void Process::Kokkos_exit(const char* str)
173{
174#ifdef KOKKOS
175 // ToDo Kokkos: try to exit more properly on device...
176 Kokkos::abort(str);
177 //Kokkos::finalize();
178#else
179 Process::exit(str);
180#endif
181}
182#endif
183
184#endif /* Process_included */
185
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
Base class of TRUST (in particular Objet_U).
Definition Process.h:48
static void mp_max_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:197
static double mp_min(double)
Definition Process.cpp:391
static int check_int_overflow(trustIdType)
Definition Process.cpp:437
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:208
static double ram_processeur()
Definition Process.cpp:605
static trustIdType mppartial_sum(trustIdType i)
Computes the partial sum of x over processors 0 to me()-1 (returns 0 on processor 0).
Definition Process.cpp:403
static KOKKOS_INLINE_FUNCTION void Kokkos_exit(const char *)
Exit routine for TRUST within a Kokkos region.
Definition Process.h:172
static int multiple_files
Definition Process.h:162
static double mp_max(double)
Definition Process.cpp:379
static void mp_sum_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:194
static bool mp_or(bool)
Definition Process.cpp:427
static int node_master()
Returns 1 if on the NUMA node master processor, 0 otherwise.
Definition Process.cpp:92
static bool is_parallel()
Definition Process.cpp:108
static Sortie & Journal(int message_level=0)
Returns a static Sortie object used as an event journal.
Definition Process.cpp:592
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
static int nproc()
Returns the number of processors in the current group. See Comm_Group::nproc() and PE_Groups::current...
Definition Process.cpp:102
static double mp_sum(double)
Computes the sum of x over all processors in the current group.
Definition Process.cpp:145
virtual ~Process()
Definition Process.h:50
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:245
static double mp_sum_as_double(int v)
Definition Process.h:97
static void imprimer_ram_totale(int all_process=0)
Definition Process.cpp:655
static void barrier()
Synchronizes all processors in the current group (waits until all processors have reached the barrier...
Definition Process.cpp:133
static bool force_single_file(const int ranks, const Nom &filename)
Definition Process.cpp:57
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:282
static int exception_sur_exit
Definition Process.h:161
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82
static void mp_min_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:200
static bool is_sequential()
Definition Process.cpp:113
static bool mp_and(bool)
Computes the logical AND of b across all processors in the current group.
Definition Process.cpp:418
Base class for output streams.
Definition Sortie.h:52