16#include <EcrFicPartageMPIIO.h>
19#include <communications.h>
20#include <Comm_Group_MPI.h>
26static void handle_error(
int errcode,
const char *str)
28 char msg[MPI_MAX_ERROR_STRING];
30 MPI_Error_string(errcode, msg, &resultlen);
31 Cerr <<
"======================" << finl;
32 Cerr << str <<
": " << msg << finl;
33 Cerr <<
"Contact TRUST support." << finl;
36#define MPI_CHECK(fn) { int errcode; errcode = fn;\
37 if (errcode != MPI_SUCCESS) handle_error(errcode, #fn); }
74 mpi_comm = MPI_COMM_WORLD;
75 int MPI_OPEN = mode == ios::app ? MPI_MODE_APPEND : MPI_MODE_CREATE;
76 int MPI_MODE = (mode == ios::app || ios::out) ? MPI_MODE_WRONLY : MPI_MODE_RDONLY;
77 MPI_CHECK(MPI_File_open(mpi_comm, (
char*)name, MPI_OPEN|MPI_MODE, MPI_INFO_NULL, &mpi_file_));
79 MPI_File_set_errhandler(mpi_file_,MPI_ERRORS_ARE_FATAL);
89 (*this)<<marq.getChar();
104 if (mpi_file_) MPI_File_close(&mpi_file_);
109void EcrFicPartageMPIIO::check()
113 Cerr <<
"Only master process can call EcrFicPartageMPIIO::operator <<(...)" << finl;
117 MPI_File_get_position(mpi_file_, &offset);
119 MPI_File_get_byte_offset(mpi_file_, offset, &disp);
122 Cerr <<
"Error in EcrFicPartageMPIIO::check()" << finl;
123 Cerr <<
"Decalage : disp_= " << (int)disp_ <<
" disp=" << (
int)disp << finl;
124 Cerr <<
"Contact TRUST support." << finl;
129void EcrFicPartageMPIIO::write(MPI_Datatype MPI_TYPE,
const void* ob)
133 bool convert =
false;
134 if (MPI_TYPE == MPI_INT || MPI_TYPE == MPI_UNSIGNED)
137 MPI_Datatype MPI_TYPE2 = MPI_TYPE;
138 const void * ob2 = ob;
140 unsigned long u_val = 0;
143 if (MPI_TYPE == MPI_INT)
145 l_val = *(
static_cast<const int *
>(ob));
146 MPI_TYPE2 = MPI_LONG;
150 else if (MPI_TYPE == MPI_UNSIGNED)
152 u_val = *(
static_cast<const unsigned *
>(ob));
153 MPI_TYPE2 = MPI_UNSIGNED_LONG;
157 Process::exit(
"EcrFicPartageMPIIO::write() -- Unexpected type!!");
160 MPI_Type_size(MPI_TYPE2, &size);
161 MPI_File_write(mpi_file_, ob2, 1, MPI_TYPE2, &mpi_status_);
181 Cerr <<
"Unknown separator in EcrFicPartageMPIIO::operator <<" << finl;
190 int size=(int)strlen(ob) + 1;
192 for (
int i=0; i<size; i++)
193 write(MPI_CHAR, &ob[i]);
199 return (*
this) << str.c_str();
207 (*
this)<<std::to_string(ob).c_str();
214 write(MPI_UNSIGNED, &ob);
216 (*
this)<<std::to_string(ob).c_str();
223 write(MPI_LONG, &ob);
225 (*
this)<<std::to_string(ob).c_str();
232 write(MPI_LONG_LONG, &ob);
234 (*
this)<<std::to_string(ob).c_str();
241 write(MPI_UNSIGNED_LONG, &ob);
243 (*
this)<<std::to_string(ob).c_str();
250 write(MPI_FLOAT, &ob);
252 (*
this)<<std::to_string(ob).c_str();
258 write(MPI_DOUBLE, &ob);
260 (*
this)<<std::to_string(ob).c_str();
272 assert(n < std::numeric_limits<int>::max());
274 Process::exit(
"EcrFicPartageMPIIO::put() not implemented for cross bitness (writing 'int' in a 64b file for example!");
275 return put(MPI_UNSIGNED, ob, (
int)n);
280 assert(n < std::numeric_limits<int>::max());
282 Process::exit(
"EcrFicPartageMPIIO::put() not implemented for cross bitness (writing 'int' in a 64b file for example!");
283 return put(MPI_INT, ob, (
int)n);
288 assert(n < std::numeric_limits<int>::max());
289 return put(MPI_LONG, ob, (
int)n);
294 assert(n < std::numeric_limits<int>::max());
295 return put(MPI_LONG_LONG, ob, (
int)n);
300 assert(n < std::numeric_limits<int>::max());
301 return put(MPI_FLOAT, ob, (
int)n);
306 assert(n < std::numeric_limits<int>::max());
307 return put(MPI_DOUBLE, ob, (
int)n);
326 MPI_Type_size(etype,&sizeof_etype);
329 MPI_Datatype filetype;
330 MPI_Type_contiguous(n, etype, &filetype);
331 MPI_Type_commit(&filetype);
334 envoyer_broadcast(disp_, 0);
339 char* ROMIO_HINTS=getenv(
"ROMIO_HINTS");
340 if (ROMIO_HINTS==
nullptr)
342 Cerr <<
"Warning, no ROMIO_HINTS detected on your massive parallel calculation." << finl;
343 Cerr <<
"Performances of MPI I/O could be improved with ROMIO hints." << finl;
344 Cerr <<
"Contact TRUST support." << finl;
350 MPI_Info_create(&mpi_info);
368 MPI_File_set_view(mpi_file_, disp_me, etype, filetype, (
char*)
"native", mpi_info);
371 statistics().
begin_count(STD_COUNTERS::IO_EcrireFicPartageMPIIO,statistics().get_last_opened_counter_level()+1);
372 MPI_File_write_all(mpi_file_, (
void*)ob, n, etype, MPI_STATUS_IGNORE);
373 statistics().
end_count(STD_COUNTERS::IO_EcrireFicPartageMPIIO,1,n * sizeof_etype);
376 disp_+=
mp_sum(n) * sizeof_etype;
379 MPI_File_set_view(mpi_file_, disp_, MPI_BYTE, MPI_BYTE, (
char*)
"native", MPI_INFO_NULL);
382 MPI_Info_free(&mpi_info);
383 MPI_Type_free(&filetype);
bool bin_
Is this a binary flux?
bool is_64b_
Will we be reading/writing in 64b? (Init in ctor to avoid including arch.h probably).
bool must_convert() const
Whether to convert an int into a long when reading/writing out data.
Class to use MPI-IO to write in a single file.
~EcrFicPartageMPIIO() override
Class defining operators and methods for all reading operation in an input flow (file,...
classe Objet_U Cette classe est la classe de base des Objets de TRUST
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
static const Comm_Group & current_group()
renvoie une reference au groupe de processeurs actif courant
void begin_count(const STD_COUNTERS &std_cnt, int counter_lvl=-100000)
void end_count(const std::string &custom_count_name, int count_increment=1, long int quantity_increment=0)
End the count of a counter and update the counter values.
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 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 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),...
Cette classe est a la classe C++ ofstream ce que la classe Sortie est a la classe C++ ostream Elle re...
SFichier(const char *name, IOS_OPEN_MODE mode=ios::out)
Separateur pour les fichiers.
const Type & get_type() const
virtual int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out)
Classe de base des flux de sortie.
virtual int put(const unsigned *ob, std::streamsize n, std::streamsize nb_colonnes=1)
Sortie & operator<<(ostream &(*f)(ostream &))