TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Schema_Comm.h
1/****************************************************************************
2* Copyright (c) 2024, 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 Schema_Comm_included
17#define Schema_Comm_included
18
19#include <TRUSTArray.h>
20#include <TRUST_Ref.h>
21
22class Comm_Group;
23
24// These objects store a communication graph between
25// processors: each proc. has a list of processors to send to
26// and a list of processors to receive from.
27//
28// The group is the set of processors on which it is GUARANTEED
29// that the following methods will be called SIMULTANEOUSLY on all
30// processors in the group:
31// - begin_comm()
32// - set_send_recv_pe_list(...)
33// - echange_taille_et_messages()
34// - end_comm()
35//
36// In particular: it is forbidden to use these methods inside
37// a loop that is not executed the same number of times by all
38// processors in the group, nor inside an "if() { }" whose
39// execution is not identical on all processors in the group.
40//
41// It is forbidden to start a new communication while another is
42// in progress (a communication always ends with "end_comm()")
43// In particular, it is forbidden to use "envoyer", "recevoir" and
44// shared disk files between the first call to schema.send_buffer()
45// and "terminer()". Be very careful about all methods used between
46// these two calls!
47//
48// On a given PE, an exchange sequence must be built as follows:
49// schema.begin_comm()
50// schema.send_buffer(pe1) << data_to_send;
51// schema.send_buffer(pe2) << data_to_send;
52// ...
53// schema.echanger_taille_et_messages();
54// schema.recv_buffer(pe2) >> data_to_recv;
55// schema.recv_buffer(pe3) >> data_to_recv;
56// ...
57// schema.end_comm();
58//
59// Communication is not necessarily symmetric: a processor can send
60// a message to one processor and receive from another.
61// However, the user guarantees that the processor lists provided in
62// send_pe_list and recv_pe_list satisfy the principle "you listen when I speak!"
63// (i.e., processor A belongs to send_pe_list on processor B
64// if and only if processor B belongs to recv_pe_list on processor A).
65
66// Modif BM 20/06/2013: adding set_all_to_allv_flag. If the flag is set, the communication
67// scheme uses MPI_alltoallv instead of ISend IRecv. To try to solve
68// problems encountered on supermuc in the file read/write routine
69// (schema where everyone writes to processor 0 => error allocating MPI_requests).
70
73class InputCommBuffer;
74class Comm_Group;
75class Entree;
76class Sortie;
77
79{
80public:
84
85 void set_group(const Comm_Group& group); // Obsolete
86 const Comm_Group& get_group() const;
87
88 const Schema_Comm& operator= (const Schema_Comm&);
89 void set_send_recv_pe_list(const ArrOfInt& send_pe_list, const ArrOfInt& recv_pe_list, const int me_to_me = 0);
90
91 void begin_comm() const; // Status transitions to WRITING
92 // Allowed when status_ == WRITING:
93 Sortie& send_buffer(int num_PE) const;
94 void echange_taille_et_messages() const; // Status transitions to EXCHANGED
95 void echange_messages(const ArrOfInt& recv_size) const; // Status transitions to EXCHANGED
96 // Allowed when status_ == EXCHANGED:
97 Entree& recv_buffer(int num_PE) const;
98 void end_comm() const; // Status transitions to RESET
99 // Accessors:
100 const ArrOfInt& get_send_pe_list() const;
101 const ArrOfInt& get_recv_pe_list() const;
102
104
105protected:
106 void echange_taille(const ArrOfInt& send_size, ArrOfInt& recv_size) const;
107 void echange_messages(const ArrOfInt& send_size, const ArrOfInt& recv_size) const;
108 // Status transitions to EXCHANGED
109 void check_send_recv_pe_list() const;
110
111 // A single status for all exchanges: concurrent access to the class is not supported
112 // because we want to limit the number of buffers and the number of "outstanding requests".
113 // Therefore: it is forbidden to start a new communication if the buffers
114 // are currently in use.
117 static OutputCommBuffer& obuffer(int pe);
118 static InputCommBuffer& ebuffer(int pe);
119
120 ArrOfInt send_pe_list_; // List of processors to send to
121 ArrOfInt recv_pe_list_; // List of processors to receive from
122 int me_to_me_; // Flag: is sending messages to oneself allowed?
123 OBS_PTR(Comm_Group) ref_group_;// Group of processors that will communicate
124
125 int use_all_to_allv_; // Flag, which type of communication should be used?
126private:
127 // Pointers are stored in a specific class (destructor of static members
128 // called automatically at end of execution to free memory).
129 static InOutCommBuffers buffers_;
130 static int n_buffers_;
131};
132
134{
135public:
136 //void echange_taille();
137 //void echange_messages() const; // Statut passe a EXCHANGED
138 const ArrOfInt& get_send_size() const;
139 const ArrOfInt& get_recv_size() const;
140protected:
141 ArrOfInt send_size_; // Size of messages to send in bytes
142 ArrOfInt recv_size_; // Size of messages to receive in bytes
143};
144
145#endif
: This class describes a group of processors on which
Definition Comm_Group.h:37
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
: Helper class used exclusively by Schema_Comm.
Tool class used exclusively by Schema_Comm.
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.
ArrOfInt recv_pe_list_
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.
int use_all_to_allv_
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
ArrOfInt send_pe_list_
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.
void set_all_to_allv_flag(int x)
OBS_PTR(Comm_Group) ref_group_
static Static_Status status_
Schema_Comm()
Constructs a new communication schema.
Base class for output streams.
Definition Sortie.h:52