TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Parallel_io_parameters.cpp
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#include <Parallel_io_parameters.h>
17#include <Param.h>
18#include <IJK_Lata_writer.h>
19#include <Interprete_bloc.h>
20#include <Perf_counters.h>
21#include <IJK_tools.h>
22
23Implemente_instanciable(Parallel_io_parameters, "Parallel_io_parameters", Interprete);
24
25// XD Parallel_io_parameters interprete Parallel_io_parameters BRACE Object to handle parallel files in IJK
26// XD_CONT discretization
27
28// Reasonable default value for typical machines nowadays
29Size_t Parallel_io_parameters::max_block_size_ = (Size_t) 0; // for the moment, deactivate parallel write by default 1024*1024*64;
30
31// 0 means that the number of writing processes will be guessed depending on the
32// number of compute processors
34
35
37{
39 return os;
40}
41
43{
44 return is;
45}
46
48{
49 int bs_bytes = -1;
50 int bs = (int) (max_block_size_ >> 20);
52 Nom ijk_name_write, ijk_name_read;
53
54 Param param(que_suis_je());
55 param.ajouter("block_size_bytes", &bs_bytes); // XD_ADD_P entier
56 // XD_CONT File writes will be performed by chunks of this size (in bytes). This parameter will not be taken into
57 // XD_CONT account if block_size_megabytes has been defined
58 param.ajouter("block_size_megabytes", &bs); // XD_ADD_P entier
59 // XD_CONT File writes will be performed by chunks of this size (in megabytes). The size should be a multiple of the
60 // XD_CONT GPFS block size or lustre stripping size (typically several megabytes)
61 param.ajouter("writing_processes", &n); // XD_ADD_P entier
62 // XD_CONT This is the number of processes that will write concurrently to the file system (this must be set according
63 // XD_CONT to the capacity of the filesystem, set to 1 on small computers, can be up to 64 or 128 on very large
64 // XD_CONT systems).
65 param.ajouter("bench_ijk_splitting_write", &ijk_name_write); // XD_ADD_P chaine
66 // XD_CONT Name of the splitting object we want to use to run a parallel write bench (optional parameter)
67 param.ajouter("bench_ijk_splitting_read", &ijk_name_read); // XD_ADD_P chaine
68 // XD_CONT Name of the splitting object we want to use to run a parallel read bench (optional parameter)
69 param.lire_avec_accolades(is);
70
71 if (bs < 0)
72 {
73 Cerr << "Error in Parallel_io_parameters::interpreter: block_size is negative" << finl;
75 }
76 if (n < 0)
77 n = 0;
78
79 max_block_size_ = (long long) bs * 1024 * 1024;
80 if (bs_bytes >= 0)
81 max_block_size_ = (long long) bs_bytes; // A buffer smaller than 1MB is usefull only for debugging...
82
84
85 Cerr << "Parallel_io_parameters: blocksize= " << bs << " MB, nb writing processes= "
86 << get_nb_writing_processes() << finl;
87
88 if (ijk_name_write != "??")
89 {
90 run_bench_write(ijk_name_write);
91 }
92 if (ijk_name_read != "??")
93 {
94 run_bench_read(ijk_name_read);
95 }
96 return is;
97}
98
100{
101 if (nb_writing_processes_ <= 0)
102 {
103 // Determine automatically:
104 // Reasonable default value for the number of writing processes (one per node, but no more than 16)
105 // Assume 24 cores per node...
106 int n = Process::nproc() / 24;
107 if (n > 16)
108 n = 16;
109 if (n == 0)
110 n = 1;
111 return n;
112 }
114}
115
116void Parallel_io_parameters::run_bench_write(const Nom& ijk_splitting_name)
117{
118 // Get the mesh:
119 const Domaine_IJK& splitting = ref_cast(Domaine_IJK, Interprete_bloc::objet_global(ijk_splitting_name));
120 // Build a velocity field and a scalar field:
121 IJK_Field_double vx, vy, vz;
122 vx.allocate(splitting, Domaine_IJK::FACES_I,0);
123 vy.allocate(splitting, Domaine_IJK::FACES_J,0);
124 vz.allocate(splitting, Domaine_IJK::FACES_K,0);
125
126 set_field_data(vx,Nom("x*0.9+y*0.09*0.001+z*0.009"));
127 set_field_data(vy,Nom("1.+x*0.9+y*0.09+z*0.009"));
128 set_field_data(vz,Nom("-1.+x*0.9+y*0.09+z*0.009"));
129
130 dumplata_header("test.lata", vx);
131 dumplata_newtime("test.lata", 0.);
132
133 statistics().set_nb_time_steps_elapsed(0);
134 statistics().create_custom_counter("Parallel_io benchmark",1,"IJK");
135 statistics().begin_count("Parallel_io benchmark",statistics().get_last_opened_counter_level()+1);
136 dumplata_vector("test.lata", "VELOCITY", vx, vy, vz, 1);
137 double t = statistics().get_time_since_last_open("Parallel_io benchmark");
138 statistics().end_count("Parallel_io benchmark");
139 double sz = (double) (splitting.get_nb_elem_tot(DIRECTION_I)+1)
140 * (splitting.get_nb_elem_tot(DIRECTION_J)+1)
141 * (splitting.get_nb_elem_tot(DIRECTION_K)+1)
142 * 3 * sizeof(float);
143 Nom bw = (t==0)? Nom("infty") : Nom(sz/1024/1024/1024/t);
144 Cerr << "Parallel_io_parameters benchmark write: data_size= " << sz/1024/1024/1024
145 << " GB. Time= " << t << " s. Bandwidth= "
146 << bw << " GB/s.(x3)" << finl;
147}
148
149double max_val_abs_ijk(const IJK_Field_double& residu,const IJK_Field_double& x)
150{
151 const int ni = residu.ni();
152 const int nj = residu.nj();
153 const int nk = residu.nk();
154 double m = 0.;
155 for (int k = 0; k < nk; k++)
156 {
157 for (int j = 0; j < nj; j++)
158 {
159 for (int i = 0; i < ni; i++)
160 {
161 m = std::fmax(fabs(residu(i,j,k)-x(i,j,k)), m);
162 }
163 }
164 }
165 m = Process::mp_max(m);
166 return m;
167}
168
169
170void Parallel_io_parameters::run_bench_read(const Nom& ijk_splitting_name)
171{
172 // Get the mesh:
173 const Domaine_IJK& splitting = ref_cast(Domaine_IJK, Interprete_bloc::objet_global(ijk_splitting_name));
174 // Build a velocity field and a scalar field:
175 IJK_Field_double vx, vy, vz;
176 vx.allocate(splitting, Domaine_IJK::FACES_I,0);
177 vy.allocate(splitting, Domaine_IJK::FACES_J,0);
178 vz.allocate(splitting, Domaine_IJK::FACES_K,0);
179
180 vx.data() = 1e9;
181 vy.data() = 1e9;
182 vz.data() = 1e9;
183
184 statistics().set_nb_time_steps_elapsed(0);
185 statistics().create_custom_counter("Parallel_io benchmark_read",1,"IJK");
186 statistics().begin_count("Parallel_io benchmark_read",statistics().get_last_opened_counter_level()+1);
187 lire_dans_lata("test.lata", 1 /* timestep */,
188 splitting.le_nom(),
189 "VELOCITY", vx, vy, vz);
190 double t = statistics().get_time_since_last_open("Parallel_io benchmark_read");
191 statistics().end_count("Parallel_io benchmark_read");
192
193 double sz = (double) (splitting.get_nb_elem_tot(DIRECTION_I)+1)
194 * (splitting.get_nb_elem_tot(DIRECTION_J)+1)
195 * (splitting.get_nb_elem_tot(DIRECTION_K)+1)
196 * 3 * sizeof(float);
197 Nom bw = (t==0)? Nom("infty") : Nom(sz/1024/1024/1024/t);
198 Cerr << "Parallel_io_parameters benchmark read: data_size= " << sz/1024/1024/1024
199 << " GB. Time= " << t << " s. Bandwidth= " << bw << " GB/s.(x3)" << finl;
200
201 // Check values:
202 IJK_Field_double vx2, vy2, vz2;
203 vx2.allocate(splitting, Domaine_IJK::FACES_I,0);
204 vy2.allocate(splitting, Domaine_IJK::FACES_J,0);
205 vz2.allocate(splitting, Domaine_IJK::FACES_K,0);
206
207 set_field_data(vx2,Nom("x*0.9+y*0.09*0.001+z*0.009"));
208 set_field_data(vy2,Nom("1.+x*0.9+y*0.09+z*0.009"));
209 set_field_data(vz2,Nom("-1.+x*0.9+y*0.09+z*0.009"));
210
211 double delta;
212
213 delta = max_val_abs_ijk(vx,vx2);
214 Cerr << "L2 Norm of difference on vx: " << delta << finl;
215 delta = max_val_abs_ijk(vy,vy2);
216 Cerr << "L2 Norm of difference on vy: " << delta << finl;
217 delta = max_val_abs_ijk(vz,vz2);
218 Cerr << "L2 Norm of difference on vz: " << delta << finl;
219}
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
Definition Domaine_IJK.h:47
int get_nb_elem_tot(int direction) const
Returns the total (global) number of mesh cells in requested direction.
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void allocate(const Domaine_IJK &d, Domaine_IJK::Localisation l, int ghost_size, int additional_k_layers=0, int nb_compo=1, const Nom &name=Nom(), bool external_storage=false, int monofluide=0, double rov=0., double rol=0., int use_inv_rho_in_pressure_solver=0)
static Objet_U & objet_global(const Nom &nom)
cherche l'objet demande dans l'Interprete_bloc courant (Interprete_bloc::interprete_courant()) et dan...
Classe de base des objets "interprete".
Definition Interprete.h:38
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
friend class Entree
Definition Objet_U.h:76
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static void run_bench_write(const Nom &ijk_splitting)
static void run_bench_read(const Nom &ijk_splitting)
Entree & interpreter(Entree &) override
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
int lire_avec_accolades(Entree &is)
Alias of lire_avec_accolades_depuis.
Definition Param.h:577
static double mp_max(double)
Definition Process.cpp:376
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 void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52