15#include <Schema_Comm.h>
17#include <InOutCommBuffers.h>
18#include <Comm_Group.h>
19#include <communications.h>
20#include <Comm_Group_MPI.h>
28int Schema_Comm::n_buffers_ = 0;
37 assert(pe >= 0 && pe < n_buffers_);
38 return buffers_.obuffers_[pe];
48 assert(pe >= 0 && pe < n_buffers_);
49 return buffers_.ebuffers_[pe];
53static const int BEGIN_COMM_TAG = 1;
54static const int ECHANGE_MESSAGES_COMM_TAG = 2;
55static const int END_COMM_TAG = 3;
56static const int COPY_OPERATOR_TAG = 4;
108 ref_group_ = schema.ref_group_;
114 const Comm_Group& group = ref_group_.valeur();
127 assert(&group == &(ref_group_.valeur()));
137 return ref_group_.valeur();
147 const ArrOfInt& recv_pe_list,
155 const Comm_Group& group = ref_group_.valeur();
175 const Comm_Group& group = ref_group_.valeur();
180static void exchange_data(
const ArrOfInt& send_list,
181 const ArrOfInt& send_size,
182 const char *
const *
const send_buffers,
183 const ArrOfInt& recv_list,
184 const ArrOfInt& recv_size,
185 char *
const *
const recv_buffers,
199 recv_list, recv_size, recv_buffers);
205 const int n = group.
nproc();
209 ArrOfInt a_send_size(n);
210 ArrOfInt a_send_offset(n);
211 ArrOfInt a_recv_size(n);
212 ArrOfInt a_recv_offset(n);
215 for (i = 0; i < nsend; i++)
216 a_send_size[send_list[i]] = send_size[i];
218 for (i = 0, offset = 0; i < n; i++)
220 a_send_offset[i] = offset;
221 offset += a_send_size[i];
223 const int buf_size_send = offset;
225 for (i = 0; i < nrecv; i++)
226 a_recv_size[recv_list[i]] = recv_size[i];
228 for (i = 0, offset = 0; i < n; i++)
230 a_recv_offset[i] = offset;
231 offset += a_recv_size[i];
233 const int buf_size_recv = offset;
235 char *send_buffer = (
char *) malloc(buf_size_send);
236 char *recv_buffer = (
char *) malloc(buf_size_recv);
238 for (i = 0; i < nsend; i++)
239 memcpy(send_buffer + a_send_offset[send_list[i]],
243 ref_cast(
Comm_Group_MPI, group).all_to_allv(send_buffer, a_send_size.addr(), a_send_offset.addr(),
244 recv_buffer, a_recv_size.addr(), a_recv_offset.addr());
246 for (i = 0; i < nrecv; i++)
247 memcpy(recv_buffers[i],
248 recv_buffer + a_recv_offset[recv_list[i]],
265 ArrOfInt& recv_size)
const
267 static ArrOfInt send_sz;
268 static ArrOfInt recv_sz;
273 const Comm_Group& group = ref_group_.valeur();
285 const char ** send_buffers =
new const char* [n_send];
286 char ** recv_buffers =
new char* [n_recv];
289 send_sz =
sizeof(int);
291 for (i = 0; i < n_send; i++)
292 send_buffers[i] = (
char*) (& send_size[i]);
295 recv_sz =
sizeof(int);
297 for (i = 0; i < n_recv; i++)
298 recv_buffers[i] = (
char*) (& recv_size[i]);
305 delete[] recv_buffers;
306 delete[] send_buffers;
316 const ArrOfInt& recv_size)
const
319 const Comm_Group& group = ref_group_.valeur();
328 const char ** send_buffers =
new const char* [n_send];
329 char ** recv_buffers =
new char* [n_recv];
332 for (i = 0; i < n_recv; i++)
335 int size = recv_size[i];
337 recv_buffers[i] = buf.reserve_buffer(size);
339 for (i = 0; i < n_send; i++)
345 assert(send_size[i] == buf.get_buffer_size());
346 send_buffers[i] = buf.get_buffer();
354 delete[] recv_buffers;
355 delete[] send_buffers;
358 for (i = 0; i < n_recv; i++)
371 buf.create_stream_from_output_stream(obuf);
385 static ArrOfInt send_size;
386 static ArrOfInt recv_size;
390 for (i = 0; i < n_send; i++)
411 ArrOfInt send_size(n_send);
413 for (i = 0; i < n_send; i++)
420 ArrOfInt check_recv_size;
422 if (!(check_recv_size == recv_size))
424 Cerr <<
"Error in Schema_Comm::echange_messages : bad recv_size" << finl;
439 const Comm_Group& group = ref_group_.valeur();
448 for (i = 0; i < n; i++)
454 for (i = 0; i < n; i++)
471static int check_PE_in_list(
int num_pe,
const ArrOfInt& list)
475 for (i = 0; i < n && list[i] != num_pe; i++);
566 for (i = 0; i < n1; i++)
570 for (i = 0; i < n2; i++)
582 fail2 = !(recv_list == copie);
587 Cerr <<
"Error in Schema_Comm::check_send_recv_pe_list(), see .log files" << finl;
592 Process::Journal() <<
"processor ranks not in current group: current group size = " << np;
594 Process::Journal() <<
"recv_list should be this one:\n" << recv_list << finl;
: Class Comm_Group_MPI, derived from the abstract class Comm_Group.
: This class describes a group of processors on which
static int check_enabled()
virtual void send_recv_finish() const =0
int nproc() const
Returns the number of processors in the group *this.
virtual void send_recv_start(const ArrOfInt &send_list, const ArrOfInt &send_size, const char *const *const send_buffers, const ArrOfInt &recv_list, const ArrOfInt &recv_size, char *const *const recv_buffers, TypeHint typehint=CHAR) const =0
virtual void barrier(int tag) const =0
Class defining operators and methods for all reading operation in an input flow (file,...
Tool class used exclusively by Schema_Comm.
static const Comm_Group & current_group()
Returns a reference to the current active processor group.
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 double mp_sum(double)
Computes the sum of x over all processors in the current group.
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.
const ArrOfInt & get_send_size() const
Returns a reference to an array containing, for each processor in send_pe_list_, the size in bytes of...
const ArrOfInt & get_recv_size() const
Returns a reference to an array containing, for each processor in send_pe_list_, the size in bytes of...
void echange_messages(const ArrOfInt &recv_size) const
Launches the data exchange.
static InputCommBuffer & ebuffer(int pe)
Accessor to a member of the ebuffers_ array (with verification).
const Schema_Comm & operator=(const Schema_Comm &)
Copy operator: copies the list of communicating processors.
void set_group(const Comm_Group &group)
Obsolete method. The group associated with the schema is the current group at the time the schema is ...
const Comm_Group & get_group() const
Returns the group associated with the schema.
void echange_taille_et_messages() const
Launches the data exchange between all processors.
~Schema_Comm()
Destructs a communication schema.
Sortie & send_buffer(int num_PE) const
Returns the buffer corresponding to processor num_PE to stack data to send.
static OutputCommBuffer & obuffer(int pe)
Accessor to a member of the obuffers_ array (with verification).
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 echange_taille(const ArrOfInt &send_size, ArrOfInt &recv_size) const
Transmits the size of messages to send to the processors that will receive them.
const ArrOfInt & get_recv_pe_list() const
void begin_comm() const
Reserves communication buffers for a new communication.
void check_send_recv_pe_list() const
Verifies that send/recv_pe_list satisfy the property "you listen when I speak".
const ArrOfInt & get_send_pe_list() const
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.
static Static_Status status_
Schema_Comm()
Constructs a new communication schema.
Base class for output streams.
_SIZE_ size_array() const
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)