16#include <InOutCommBuffers.h>
17#include <communications.h>
18#include <Schema_Comm.h>
19#include <TRUSTArrays.h>
63bool envoyer_buffered_(
const T& objet,
int source,
int cible,
int canal)
69 if (source != moi && source != -1)
79 const int n = grp.
nproc();
80 for (
int i = 0; i < n; i++)
84 grp.
send(i, &sz,
sizeof(
int), canal);
85 grp.
send(i, data, sz, canal);
91 grp.
send(cible, &sz,
sizeof(
int), canal);
92 grp.
send(cible, data, sz, canal);
101bool recevoir_buffered_(T& objet,
int source,
int cible,
int canal)
107 if (cible != moi && cible != -1)
112 grp.
recv(source, &sz,
sizeof(
int), canal);
115 grp.
recv(source, data, sz, canal);
128bool envoyer_broadcast_buffered_(T& objet,
int source)
131 if (grp.
rank() == source)
154bool envoyer(
const Objet_U& t,
int source,
int cible,
int canal)
156 return envoyer_buffered_(t, source, cible, canal);
159bool envoyer(
const Objet_U& t,
int cible,
int canal)
161 return envoyer_buffered_(t,
Process::me(), cible, canal);
164bool recevoir(
Objet_U& t,
int source,
int cible,
int canal)
166 return recevoir_buffered_(t, source, cible, canal);
169bool recevoir(
Objet_U& t,
int source,
int canal)
171 return recevoir_buffered_(t, source,
Process::me(), canal);
174bool envoyer_broadcast(
Objet_U& t,
int source)
176 return envoyer_broadcast_buffered_(t, source);
181bool envoyer_all_to_all_(
const T& src, T& dest)
187 const int nproc = grp.
nproc();
188 const int moi = grp.
rank();
189 dest[moi] = src[moi];
190 ArrOfInt send_pe_list(1);
191 ArrOfInt recv_pe_list(1);
192 for (
int p = 1; p < nproc; p++)
194 const int send_to = (moi + p) % nproc;
195 const int recv_from = (moi + nproc - p) % nproc;
196 send_pe_list[0] = send_to;
197 recv_pe_list[0] = recv_from;
210 return envoyer_all_to_all_(src, dest);
215 return envoyer_all_to_all_(src, dest);
221 return envoyer_all_to_all_(src, dest);
233bool envoyer_all_to_all(std::vector<long long>& src, std::vector<long long>& dest)
236 assert(
static_cast<int>(src.size()) == grp.
nproc());
237 assert(
static_cast<int>(dest.size()) == grp.
nproc());
238 if (src.data() == dest.data())
240 std::vector<long long> tmp(grp.
nproc(),0);
241 grp.
all_to_all(src.data(), tmp.data(),
sizeof(
long long));
246 grp.
all_to_all(src.data(), dest.data(),
sizeof(
long long));
263bool reverse_send_recv_pe_list(
const ArrOfInt& src_list, ArrOfInt& dest_list)
266 const int np = grp.
nproc();
267 assert(src_list.
size_array() == 0 || max_array(src_list) < np);
268 assert(src_list.
size_array() == 0 || min_array(src_list) >= 0);
272 for (i = 0; i < src_size; i++)
274 const int pe = src_list[i];
277 ArrOfInt flag_recv(np);
278 envoyer_all_to_all(flag, flag_recv);
281 for (i = 0; i < np; i++)
296void envoyer_all_to_all(
const DoubleTab& src, DoubleTab& dest)
306 envoyer_all_to_all(src, tmp);
311 const int sz = src.
size() / grp.
nproc() * (int)
sizeof(
double);
324 const int sz = src.
size() / grp.
nproc() * (int)
sizeof(T);
331 const int sz = src.
size() * (int)
sizeof(T);
346 const int sz = src.
size() / grp.
nproc() * (int)
sizeof(T);
353 const int sz = src.
size() * (int)
sizeof(T);
359void envoyer_gather(
const DoubleTab& src, DoubleTab& dest,
int root)
361 envoyer_gather_(src,dest,root);
364void envoyer_gather(
const IntTab& src, IntTab& dest,
int root)
366 envoyer_gather_(src,dest,root);
369void envoyer_all_gather(
const DoubleTab& src, DoubleTab& dest)
371 envoyer_all_gather_(src,dest);
374void envoyer_all_gather(
const IntTab& src, IntTab& dest)
376 envoyer_all_gather_(src,dest);
379void envoyer_all_gatherv(
const DoubleTab& src, DoubleTab& dest,
const IntTab& recv_size)
383 assert(dest.
size_array()==local_somme_vect(recv_size));
386 const int nbprocs = (int)grp.
nproc();
388 std::vector<int> sz(nbprocs);
389 for (
int p=0; p<nbprocs; p++)
390 sz[p] = recv_size[p] * (
int)
sizeof(double);
392 int sz0 = src.
size() * (int)
sizeof(
double);
394 std::vector<int> displs(nbprocs);
396 for (
int p=1; p<nbprocs; p++)
397 displs[p] = displs[p-1]+sz[p-1];
414bool is_parallel_object(
const int x)
422bool is_parallel_object(
const trustIdType x)
433bool is_parallel_object(
const double x)
442 return tab_y[0] == tab_y[1];
445template <
class T>
int compare(
const Objet_U& a,
const Objet_U& b,
int& erreur)
449 const T& a_ =
static_cast<const T&
> (a);
450 const T& b_ =
static_cast<const T&
> (b);
464bool is_parallel_object(
const Objet_U& obj)
471 for (
int i = 1; i < n; i++)
473 recevoir(copie, i, 67 );
486 if (compare<IntTab> (obj, obj2, erreur)) { }
487 else if (compare<DoubleTab> (obj, obj2, erreur)) { }
488 else if (compare<IntVect> (obj, obj2, erreur)) { }
489 else if (compare<DoubleVect> (obj, obj2, erreur)) { }
490 else if (compare<ArrOfInt> (obj, obj2, erreur)) { }
491 else if (compare<ArrOfDouble> (obj, obj2, erreur)) { }
492 else if (compare<Motcle> (obj, obj2, erreur)) { }
493 else if (compare<Nom> (obj, obj2, erreur)) { }
496 Cerr <<
"Internal error in is_parallel_objec() : it is not coded for " << obj.
que_suis_je() << finl;
506 envoyer(copie, 0, 67 );
509 envoyer_broadcast(erreur, 0 );
518void assert_parallel(
const Objet_U& obj)
523 if (!is_parallel_object(obj))
525 Cerr <<
"Fatal error in assert_parallel(const Objet_U & obj): objects do not match, see log files" << finl;
527 <<
"This processor has this object : " << obj.
que_suis_je() << finl
: This class describes a group of processors on which
static int check_enabled()
virtual void all_gather(const void *src_buffer, void *dest_buffer, int data_size) const =0
virtual void send(int pe, const void *buffer, int size, int tag) const =0
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 all_gatherv(const void *src_buffer, void *dest_buffer, int send_size, const int *recv_size, const int *displs) const =0
virtual void broadcast(void *buffer, int size, int pe_source) const =0
virtual void mp_collective_op(const double *x, double *resu, int n, Collective_Op op) const =0
virtual void all_to_all(const void *src_buffer, void *dest_buffer, int data_size) const =0
virtual void recv(int pe, void *buffer, int size, int tag) const =0
virtual void gather(const void *src_buffer, void *dest_buffer, int data_size, int root) const =0
Base class for TRUST objects (Objet_U).
const Nom & que_suis_je() const
Returns the string identifying the class.
Tool class used exclusively by Schema_Comm.
const char * get_buffer()
static const Comm_Group & current_group()
Returns a reference to the current active processor group.
static double mp_min(double)
static double mp_max(double)
static Sortie & Journal(int message_level=0)
Returns a static Sortie object used as an event journal.
static int nproc()
Returns the number of processors in the current group. See Comm_Group::nproc() and PE_Groups::current...
static void barrier()
Synchronizes all processors in the current group (waits until all processors have reached the barrier...
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.
void echange_taille_et_messages() const
Launches the data exchange between all processors.
Sortie & send_buffer(int num_PE) const
Returns the buffer corresponding to processor num_PE to stack data to send.
void end_comm() const
Clears the buffers and releases resources: reading of received data from buffers is complete.
Entree & recv_buffer(int num_PE) const
Returns the buffer corresponding to processor num_PE to read received data.
void begin_comm() const
Reserves communication buffers for a new communication.
void set_send_recv_pe_list(const ArrOfInt &send_pe_list, const ArrOfInt &recv_pe_list, const int me_to_me=0)
Defines the list of processors to send data to and receive data from.
Represents a an array of int/int64/double/... values.
_SIZE_ size_array() const
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
N-dimensional array for N <= 4.
_SIZE_ dimension(int d) const
const Objet_U & valeur() const