Pstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Pstream
26 
27 Description
28  Inter-processor communications stream
29 
30 SourceFiles
31  Pstream.C
32  gatherScatter.C
33  combineGatherScatter.C
34  gatherScatterList.C
35  exchange.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Pstream_H
40 #define Pstream_H
41 
42 #include "UPstream.H"
43 #include "DynamicList.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class Pstream Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class Pstream
55 :
56  public UPstream
57 {
58 
59 protected:
60 
61  // Protected data
62 
63  //- Transfer buffer
65 
66 public:
67 
68  // Declare name of the class and its debug switch
69  ClassName("Pstream");
70 
71 
72  // Constructors
73 
74  //- Construct given optional buffer size
76  (
77  const commsTypes commsType,
78  const label bufSize = 0
79  )
80  :
81  UPstream(commsType),
82  buf_(0)
83  {
84  if (bufSize)
85  {
86  buf_.setCapacity(bufSize + 2*sizeof(scalar) + 1);
87  }
88  }
89 
90 
91  // Gather and scatter
92 
93  //- Gather data. Apply bop to combine Value
94  // from different processors
95  template<class T, class BinaryOp>
96  static void gather
97  (
98  const List<commsStruct>& comms,
99  T& Value,
100  const BinaryOp& bop,
101  const int tag,
102  const label comm
103  );
104 
105  //- Like above but switches between linear/tree communication
106  template<class T, class BinaryOp>
107  static void gather
108  (
109  T& Value,
110  const BinaryOp& bop,
111  const int tag = Pstream::msgType(),
112  const label comm = Pstream::worldComm
113  );
114 
115  //- Scatter data. Distribute without modification. Reverse of gather
116  template<class T>
117  static void scatter
118  (
119  const List<commsStruct>& comms,
120  T& Value,
121  const int tag,
122  const label comm
123  );
124 
125  //- Like above but switches between linear/tree communication
126  template <class T>
127  static void scatter
128  (
129  T& Value,
130  const int tag = Pstream::msgType(),
131  const label comm = Pstream::worldComm
132  );
133 
134  // Combine variants. Inplace combine values from processors.
135  // (Uses construct from Istream instead of <<)
136 
137  template<class T, class CombineOp>
138  static void combineGather
139  (
140  const List<commsStruct>& comms,
141  T& Value,
142  const CombineOp& cop,
143  const int tag,
144  const label comm
145  );
146 
147  //- Like above but switches between linear/tree communication
148  template<class T, class CombineOp>
149  static void combineGather
150  (
151  T& Value,
152  const CombineOp& cop,
153  const int tag = Pstream::msgType(),
154  const label comm = Pstream::worldComm
155  );
156 
157  //- Scatter data. Reverse of combineGather
158  template<class T>
159  static void combineScatter
160  (
161  const List<commsStruct>& comms,
162  T& Value,
163  const int tag,
164  const label comm
165  );
166 
167  //- Like above but switches between linear/tree communication
168  template<class T>
169  static void combineScatter
170  (
171  T& Value,
172  const int tag = Pstream::msgType(),
173  const label comm = Pstream::worldComm
174  );
175 
176  // Combine variants working on whole List at a time.
177 
178  template<class T, class CombineOp>
179  static void listCombineGather
180  (
181  const List<commsStruct>& comms,
182  List<T>& Value,
183  const CombineOp& cop,
184  const int tag,
185  const label comm
186  );
187 
188  //- Like above but switches between linear/tree communication
189  template<class T, class CombineOp>
190  static void listCombineGather
191  (
192  List<T>& Value,
193  const CombineOp& cop,
194  const int tag = Pstream::msgType(),
195  const label comm = Pstream::worldComm
196  );
197 
198  //- Scatter data. Reverse of combineGather
199  template<class T>
200  static void listCombineScatter
201  (
202  const List<commsStruct>& comms,
203  List<T>& Value,
204  const int tag,
205  const label comm
206  );
207 
208  //- Like above but switches between linear/tree communication
209  template<class T>
210  static void listCombineScatter
211  (
212  List<T>& Value,
213  const int tag = Pstream::msgType(),
214  const label comm = Pstream::worldComm
215  );
216 
217  // Combine variants working on whole map at a time. Container needs to
218  // have iterators and find() defined.
219 
220  template<class Container, class CombineOp>
221  static void mapCombineGather
222  (
223  const List<commsStruct>& comms,
224  Container& Values,
225  const CombineOp& cop,
226  const int tag,
227  const label comm
228  );
229 
230  //- Like above but switches between linear/tree communication
231  template<class Container, class CombineOp>
232  static void mapCombineGather
233  (
234  Container& Values,
235  const CombineOp& cop,
236  const int tag = Pstream::msgType(),
237  const label comm = UPstream::worldComm
238  );
239 
240  //- Scatter data. Reverse of combineGather
241  template<class Container>
242  static void mapCombineScatter
243  (
244  const List<commsStruct>& comms,
245  Container& Values,
246  const int tag,
247  const label comm
248  );
249 
250  //- Like above but switches between linear/tree communication
251  template<class Container>
252  static void mapCombineScatter
253  (
254  Container& Values,
255  const int tag = Pstream::msgType(),
256  const label comm = UPstream::worldComm
257  );
258 
259 
260 
261  // Gather/scatter keeping the individual processor data separate.
262  // Values is a List of size UPstream::nProcs() where
263  // Values[UPstream::myProcNo()] is the data for the current processor.
264 
265  //- Gather data but keep individual values separate
266  template<class T>
267  static void gatherList
268  (
269  const List<commsStruct>& comms,
270  List<T>& Values,
271  const int tag,
272  const label comm
273  );
274 
275  //- Like above but switches between linear/tree communication
276  template<class T>
277  static void gatherList
278  (
279  List<T>& Values,
280  const int tag = Pstream::msgType(),
281  const label comm = UPstream::worldComm
282  );
283 
284  //- Scatter data. Reverse of gatherList
285  template<class T>
286  static void scatterList
287  (
288  const List<commsStruct>& comms,
289  List<T>& Values,
290  const int tag,
291  const label comm
292  );
293 
294  //- Like above but switches between linear/tree communication
295  template<class T>
296  static void scatterList
297  (
298  List<T>& Values,
299  const int tag = Pstream::msgType(),
300  const label comm = UPstream::worldComm
301  );
302 
303 
304  // Exchange
305 
306  //- Exchange data. Sends sendData, receives into recvData, sets
307  // sizes (not bytes). sizes[p0][p1] is what processor p0 has
308  // sent to p1. Continuous data only.
309  // If block=true will wait for all transfers to finish.
310  template<class Container, class T>
311  static void exchange
312  (
313  const List<Container >&,
315  labelListList& sizes,
316  const int tag = UPstream::msgType(),
317  const label comm = UPstream::worldComm,
318  const bool block = true
319  );
320 
321 };
322 
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 } // End namespace Foam
327 
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 
330 #ifdef NoRepository
331 # include "gatherScatter.C"
332 # include "combineGatherScatter.C"
333 # include "gatherScatterList.C"
334 # include "exchange.C"
335 #endif
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 #endif
340 
341 // ************************************************************************* //
Inter-processor communications stream.
Definition: UPstream.H:58
void setCapacity(const label)
Alter the size of the underlying storage.
Definition: DynamicListI.H:109
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:63
Pstream(const commsTypes commsType, const label bufSize=0)
Construct given optional buffer size.
Definition: Pstream.H:75
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Gather data from all processors onto single processor according to some communication schedule (usual...
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
static void exchange(const List< Container > &, List< Container > &, labelListList &sizes, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, const bool block=true)
Exchange data. Sends sendData, receives into recvData, sets.
Definition: exchange.C:38
static void gather(const List< commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Gather data. Apply bop to combine Value.
Definition: gatherScatter.C:47
Inter-processor communications stream.
Definition: Pstream.H:53
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
Namespace for OpenFOAM.
Gather data from all processors onto single processor according to some communication schedule (usual...
ClassName("Pstream")
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
static void mapCombineScatter(const List< commsStruct > &comms, Container &Values, const int tag, const label comm)
Scatter data. Reverse of combineGather.
DynamicList< char > buf_
Transfer buffer.
Definition: Pstream.H:63
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
commsTypes
Types of communications.
Definition: UPstream.H:64
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:451
static void mapCombineGather(const List< commsStruct > &comms, Container &Values, const CombineOp &cop, const int tag, const label comm)
commsTypes commsType() const
Get the communications type of the stream.
Definition: UPstream.H:458
Exchange data.
static void combineScatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:261
static void combineGather(const List< commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
Variant of gather, scatter. Normal gather uses: