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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2025 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::Pstream
29 
30 Description
31  Inter-processor communications stream.
32 
33 SourceFiles
34  Pstream.C
35  PstreamBroadcast.txx
36  PstreamGather.txx
37  PstreamGatherList.txx
38  PstreamExchange.txx
39  PstreamExchangeConsensus.txx
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Foam_Pstream_H
44 #define Foam_Pstream_H
45 
46 #include "UPstream.H"
47 #include "DynamicList.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class Pstream Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class Pstream
59 :
60  public UPstream
61 {
62 protected:
63 
64  // Protected Data
65 
66  //- Allocated transfer buffer (can be used for send or receive)
68 
69 
70 public:
71 
72  //- Declare name of the class and its debug switch
73  ClassName("Pstream");
74 
75 
76  // Constructors
77 
78  //- Construct for communication type with empty buffer
80  :
82  {}
83 
84  //- Construct for communication type with given buffer size
85  Pstream(const UPstream::commsTypes commsType, int bufferSize)
86  :
88  {
89  if (bufferSize > 0)
90  {
91  transferBuf_.setCapacity(bufferSize + 2*sizeof(scalar) + 1);
92  }
93  }
94 
95 
96  // Static Functions
97 
98  // Broadcast
99 
100  //- Broadcast buffer content to all processes in communicator.
101  using UPstream::broadcast;
102 
103  //- Broadcast content (contiguous or non-contiguous) to all
104  //- communicator ranks. Does nothing in \b non-parallel.
105  template<class Type>
106  static void broadcast
107  (
108  Type& value,
109  const int communicator = UPstream::worldComm
110  );
111 
112  //- Broadcast fixed-list content (contiguous or non-contiguous) to all
113  //- communicator ranks. Does nothing in \b non-parallel.
114  template<class Type, unsigned N>
115  static void broadcast
116  (
117  FixedList<Type, N>& list,
118  const int communicator = UPstream::worldComm
119  );
120 
121  //- Broadcast multiple items to all communicator ranks.
122  //- Does nothing in \b non-parallel.
123  template<class Type, class... Args>
124  static void broadcasts
125  (
126  const int communicator,
127  Type& value,
128  Args&&... values
129  );
130 
131  //- Broadcast list content (contiguous or non-contiguous) to all
132  //- communicator ranks. Does nothing in \b non-parallel.
133  // For contiguous list data, this avoids serialization overhead,
134  // but at the expense of an additional broadcast call.
135  template<class ListType>
136  static void broadcastList
137  (
138  ListType& list,
139  const int communicator = UPstream::worldComm
140  );
141 
142 
143  // Gather/scatter : single value
144 
145  //- Implementation: gather (reduce) single element data onto
146  //- UPstream::masterNo()
147  template<class T, class BinaryOp, bool InplaceMode>
148  static void gather_algorithm
149  (
150  const UPstream::commsStructList& comms,
151  T& value,
153  BinaryOp bop,
154  const int tag,
155  const int communicator
156  );
157 
158  //- Implementation: gather (reduce) single element data onto
159  //- UPstream::masterNo() using a topo algorithm.
160  // \returns True if topo algorithm was applied
161  template<class T, class BinaryOp, bool InplaceMode>
162  static bool gather_topo_algorithm
163  (
165  T& value,
166  BinaryOp bop,
167  const int tag,
168  const int communicator
169  );
170 
171  //- Gather (reduce) data, applying \c bop to combine \c value
172  //- from different processors. The basis for Foam::reduce().
173  // A no-op for non-parallel.
174  //
175  // \tparam InplaceMode indicates that the binary operator
176  // modifies values in-place, not using assignment
177  template<class T, class BinaryOp, bool InplaceMode=false>
178  static void gather
179  (
181  T& value,
182  BinaryOp bop,
183  const int tag = UPstream::msgType(),
184  const int communicator = UPstream::worldComm
185  );
186 
187  //- Gather individual values into list locations.
188  // On master list length == nProcs, otherwise zero length.
189  // \n
190  // For \b non-parallel :
191  // the returned list length is 1 with localValue.
192  template<class T>
194  (
195  const T& localValue,
196  const int communicator = UPstream::worldComm,
198  const int tag = UPstream::msgType()
199  );
200 
201  //- Scatter individual values from list locations.
202  // On master input list length == nProcs, ignored on other procs.
203  // \n
204  // For \b non-parallel :
205  // returns the first list element (or default initialized).
206  template<class T>
207  static T listScatterValues
208  (
209  const UList<T>& allValues,
210  const int communicator = UPstream::worldComm,
212  const int tag = UPstream::msgType()
213  );
214 
215 
216  // Inplace combine (gather) : single value
217 
218  //- Forwards to Pstream::gather with an \em in-place \c cop
219  template<class T, class CombineOp>
220  static void combineGather
221  (
223  T& value,
224  CombineOp cop,
225  const int tag = UPstream::msgType(),
226  const int communicator = UPstream::worldComm
227  );
228 
229  //- Reduce inplace (cf. MPI Allreduce)
230  //- applying \c cop to inplace combine \c value
231  //- from different processors.
232  template<class T, class CombineOp>
233  static void combineReduce
234  (
236  T& value,
237  CombineOp cop,
238  const int tag = UPstream::msgType(),
239  const int communicator = UPstream::worldComm
240  );
241 
242  //- Same as Pstream::combineReduce
243  template<class T, class CombineOp>
244  static void combineAllGather
245  (
247  T& value,
248  CombineOp cop,
249  const int tag = UPstream::msgType(),
250  const int communicator = UPstream::worldComm
251  )
252  {
253  Pstream::combineReduce(value, cop, tag, communicator);
254  }
255 
256 
257  // Gather/combine variants working on entire List
258 
259  //- Implementation: gather (reduce) list element data onto
260  //- UPstream::masterNo()
261  template<class T, class BinaryOp, bool InplaceMode>
262  static void listGather_algorithm
263  (
264  const UPstream::commsStructList& comms,
265  UList<T>& values,
267  BinaryOp bop,
268  const int tag,
269  const int communicator
270  );
271 
272  //- Implementation: gather (reduce) list element data onto
273  //- UPstream::masterNo() using a topo algorithm.
274  // \returns True if topo algorithm was applied
275  template<class T, class BinaryOp, bool InplaceMode>
276  static bool listGather_topo_algorithm
277  (
280  BinaryOp bop,
281  const int tag,
282  const int communicator
283  );
284 
285  //- Gather (reduce) list elements,
286  //- applying \c bop to each list element
287  //
288  // \tparam InplaceMode indicates that the binary operator
289  // modifies values in-place, not using assignment
290  template<class T, class BinaryOp, bool InplaceMode=false>
291  static void listGather
292  (
294  UList<T>& values,
295  BinaryOp bop,
296  const int tag = UPstream::msgType(),
298  );
299 
300  //- Forwards to Pstream::listGather with an \em in-place \c cop
301  template<class T, class CombineOp>
302  static void listCombineGather
303  (
305  UList<T>& values,
306  CombineOp cop,
307  const int tag = UPstream::msgType(),
309  );
310 
311  //- Reduce list elements (list must be equal size on all ranks),
312  //- applying \c bop to each list element.
313  //
314  // \tparam InplaceMode indicates that the binary operator
315  // modifies values in-place, not using assignment
316  template<class T, class BinaryOp, bool InplaceMode=false>
317  static void listReduce
318  (
320  UList<T>& values,
321  BinaryOp bop,
322  const int tag = UPstream::msgType(),
324  );
325 
326  //- Forwards to Pstream::listReduce with an \em in-place \c cop
327  template<class T, class CombineOp>
328  static void listCombineReduce
329  (
331  UList<T>& values,
332  CombineOp cop,
333  const int tag = UPstream::msgType(),
335  );
336 
337  //- Same as Pstream::listCombineReduce
338  template<class T, class CombineOp>
339  static void listCombineAllGather
340  (
342  UList<T>& values,
343  CombineOp cop,
344  const int tag = UPstream::msgType(),
346  )
347  {
349  }
350 
351 
352  // Gather/combine variants working on Map/HashTable containers
353 
354  //- Implementation: gather (reduce) Map/HashTable containers onto
355  //- UPstream::masterNo()
356  template<class Container, class BinaryOp, bool InplaceMode>
357  static void mapGather_algorithm
358  (
359  const UPstream::commsStructList& comms,
360  Container& values,
361  BinaryOp bop,
362  const int tag,
363  const int communicator
364  );
365 
366  //- Implementation: gather (reduce) Map/HashTable containers onto
367  //- UPstream::masterNo() using a topo algorithm.
368  // \returns True if topo algorithm was applied
369  template<class Container, class BinaryOp, bool InplaceMode>
370  static bool mapGather_topo_algorithm
371  (
372  Container& values,
373  BinaryOp bop,
374  const int tag,
375  const int communicator
376  );
377 
378  //- Gather (reduce) Map/HashTable containers,
379  //- applying \c bop to combine entries from different processors.
380  //
381  // \tparam InplaceMode indicates that the binary operator
382  // modifies values in-place, not using assignment
383  template<class Container, class BinaryOp, bool InplaceMode=false>
384  static void mapGather
385  (
387  Container& values,
388  BinaryOp bop,
389  const int tag = UPstream::msgType(),
390  const int communicator = UPstream::worldComm
391  );
392 
393  //- Forwards to Pstream::mapGather with an \em in-place \c cop
394  template<class Container, class CombineOp>
395  static void mapCombineGather
396  (
398  Container& values,
399  CombineOp cop,
400  const int tag = UPstream::msgType(),
402  );
403 
404  //- Reduce inplace (cf. MPI Allreduce)
405  //- applying \c bop to combine map \c values
406  //- from different processors.
407  //- After completion all processors have the same data.
408  //
409  // Wraps mapCombineGather/broadcast (may change in the future).
410  template<class Container, class BinaryOp, bool InplaceMode=false>
411  static void mapReduce
412  (
414  Container& values,
415  BinaryOp bop,
416  const int tag = UPstream::msgType(),
418  );
419 
420  //- Forwards to Pstream::mapReduce with an \em in-place \c cop
421  template<class Container, class CombineOp>
422  static void mapCombineReduce
423  (
425  Container& values,
426  CombineOp cop,
427  const int tag = UPstream::msgType(),
429  );
430 
431  //- Same as Pstream::mapCombineReduce
432  template<class Container, class CombineOp>
433  static void mapCombineAllGather
434  (
436  Container& values,
437  CombineOp cop,
438  const int tag = UPstream::msgType(),
440  )
441  {
443  }
444 
445 
446  // Gather/scatter keeping the individual processor data separate.
447  // The values is a List of size UPstream::nProcs() where
448  // values[UPstream::myProcNo()] is the data for the current processor.
449 
450  //- Implementation: gather data, keeping individual values separate.
451  //- Output is only valid (consistent) on UPstream::masterNo()
452  template<class T>
453  static void gatherList_algorithm
454  (
455  const UPstream::commsStructList& comms,
456  UList<T>& values,
458  const int tag,
459  const int communicator
460  );
461 
462  //- Gather data, keeping individual values separate.
463  // \returns True if topo algorithm was applied
464  template<class T>
465  static bool gatherList_topo_algorithm
466  (
468  UList<T>& values,
469  const int tag,
470  const int communicator
471  );
472 
473  //- Implementation: inverse of gatherList_algorithm
474  template<class T>
475  static void scatterList_algorithm
476  (
477  const UPstream::commsStructList& comms,
478  UList<T>& values,
480  const int tag,
481  const int communicator
482  );
483 
484  //- Gather data, but keep individual values separate.
485  template<class T>
486  static void gatherList
487  (
489  UList<T>& values,
490  const int tag = UPstream::msgType(),
491  const int communicator = UPstream::worldComm
492  );
493 
494  //- Gather data, but keep individual values separate.
495  //- Uses MPI_Allgather or manual communication.
496  // After completion all processors have the same data.
497  // Wraps gatherList/scatterList (may change in the future).
498  template<class T>
499  static void allGatherList
500  (
503  const int tag = UPstream::msgType(),
505  );
506 
507 
508  // Exchange
509 
510  //- Helper: exchange sizes of sendBufs for specified send/recv ranks
511  template<class Container>
512  static void exchangeSizes
513  (
514  const labelUList& sendProcs,
515  const labelUList& recvProcs,
516  const Container& sendBufs,
517  labelList& sizes,
518  const int tag = UPstream::msgType(),
519  const int comm = UPstream::worldComm
520  );
521 
522  //- Helper: exchange sizes of sendBufs for specified neighbour ranks
523  template<class Container>
524  static void exchangeSizes
525  (
526  const labelUList& neighProcs,
527  const Container& sendBufs,
528  labelList& sizes,
529  const int tag = UPstream::msgType(),
530  const int comm = UPstream::worldComm
531  );
532 
533  //- Helper: exchange sizes of sendBufs.
534  //- The sendBufs is the data per processor (in the communicator).
535  // Returns sizes of sendBufs on the sending processor.
536  // \n
537  // For \b non-parallel : copy sizes from sendBufs directly.
538  template<class Container>
539  static void exchangeSizes
540  (
541  const Container& sendBufs,
542  labelList& recvSizes,
543  const int comm = UPstream::worldComm
544  );
545 
546  //- Exchange the \b non-zero sizes of sendBufs entries (sparse map)
547  //- with other ranks in the communicator
548  //- using non-blocking consensus exchange.
549  //
550  // Since the recvData map always cleared before receipt and sizes
551  // of zero are never transmitted, a simple check
552  // of its keys is sufficient to determine connectivity.
553  //
554  // For \b non-parallel : copy size of rank (if it exists and non-empty)
555  // from sendBufs to recvSizes.
556  //
557  // \note The message tag is adjusted internally to improve uniqueness
558  template<class Container>
559  static void exchangeSizes
560  (
561  const Map<Container>& sendBufs,
562  Map<label>& recvSizes,
563  const int tag = UPstream::msgType(),
564  const int comm = UPstream::worldComm
565  );
566 
567  //- Helper: exchange \em contiguous data.
568  //- Sends sendBufs, receives into recvBufs using predetermined receive
569  //- sizing.
570  // If wait=true will wait for all transfers to finish.
571  template<class Container, class Type>
572  static void exchange
573  (
574  const UList<Container>& sendBufs,
575  const labelUList& recvSizes,
576  List<Container>& recvBufs,
577  const int tag = UPstream::msgType(),
578  const int comm = UPstream::worldComm,
579  const bool wait = true
580  );
581 
582  //- Exchange \em contiguous data.
583  //- Sends sendBufs, receives into recvBufs.
584  // Data provided and received as container.
585  //
586  // No internal guards or resizing.
587  template<class Container, class Type>
588  static void exchange
589  (
590  const Map<Container>& sendBufs,
591  const Map<label>& recvSizes,
592  Map<Container>& recvBufs,
593  const int tag = UPstream::msgType(),
594  const int comm = UPstream::worldComm,
595  const bool wait = true
596  );
597 
598  //- Exchange \em contiguous data.
599  //- Sends sendBufs, receives into recvBufs.
600  //- Determines sizes to receive.
601  // If wait=true will wait for all transfers to finish.
602  template<class Container, class Type>
603  static void exchange
604  (
605  const UList<Container>& sendBufs,
606  List<Container>& recvBufs,
607  const int tag = UPstream::msgType(),
608  const int comm = UPstream::worldComm,
609  const bool wait = true
610  );
611 
612  //- Exchange \em contiguous data.
613  //- Sends sendBufs, receives into recvBufs.
614  //- Determines sizes to receive.
615  // If wait=true will wait for all transfers to finish.
616  template<class Container, class Type>
617  static void exchange
618  (
619  const Map<Container>& sendBufs,
620  Map<Container>& recvBufs,
621  const int tag = UPstream::msgType(),
622  const int comm = UPstream::worldComm,
623  const bool wait = true
624  );
625 
626 
627  // Non-blocking exchange
628 
629  //- Exchange \em contiguous data using non-blocking consensus (NBX)
630  //- Sends sendData, receives into recvData.
631  //
632  // Each entry of the recvBufs list is cleared before receipt.
633  // For \b non-parallel : copy own rank from sendBufs to recvBufs.
634  //
635  // \note The message tag should be chosen to be a unique value
636  // since the implementation uses probing with ANY_SOURCE !!
637  template<class Container, class Type>
638  static void exchangeConsensus
639  (
640  const UList<Container>& sendBufs,
641  List<Container>& recvBufs,
642  const int tag,
643  const int comm,
644  const bool wait = true
645  );
646 
647  //- Exchange \em contiguous data using non-blocking consensus (NBX)
648  //- Sends sendData, receives into recvData.
649  //
650  // Each \em entry of the recvBufs map is cleared before receipt,
651  // but the map itself if not cleared. This allows the map to preserve
652  // allocated space (eg DynamicList entries) between calls.
653  //
654  // For \b non-parallel : copy own rank (if it exists and non-empty)
655  // from sendBufs to recvBufs.
656  //
657  // \note The message tag should be chosen to be a unique value
658  // since the implementation uses probing with ANY_SOURCE !!
659  template<class Container, class Type>
660  static void exchangeConsensus
661  (
662  const Map<Container>& sendBufs,
663  Map<Container>& recvBufs,
664  const int tag,
665  const int comm,
666  const bool wait = true
667  );
668 
669  //- Exchange \em contiguous data using non-blocking consensus (NBX)
670  //- Sends sendData returns receive information.
671  //
672  // For \b non-parallel : copy own rank (if it exists and non-empty)
673  //
674  // \note The message tag should be chosen to be a unique value
675  // since the implementation uses probing with ANY_SOURCE !!
676  template<class Container, class Type>
678  (
679  const Map<Container>& sendBufs,
680  const int tag,
681  const int comm,
682  const bool wait = true
683  );
684 
685 
686  // Housekeeping
687 
688  //- \deprecated(2024-01) Broadcast data
689  template<class T>
690  FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
691  static void scatter
692  (
693  T& value,
694  const int tag = UPstream::msgType(),
695  const int comm = UPstream::worldComm
696  )
697  {
698  Pstream::broadcast(value, comm);
699  }
700 
701  //- \deprecated(2024-01) Broadcast data
702  template<class T>
703  FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
704  static void combineScatter
705  (
706  T& value,
707  const int tag = UPstream::msgType(),
708  const int comm = UPstream::worldComm
709  )
710  {
711  Pstream::broadcast(value, comm);
712  }
713 
714  //- \deprecated(2024-01) Broadcast data
715  template<class T>
716  FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
717  static void listCombineScatter
718  (
719  List<T>& value,
720  const int tag = UPstream::msgType(),
721  const int comm = UPstream::worldComm
722  )
723  {
724  Pstream::broadcast(value, comm);
725  }
726 
727  //- \deprecated(2024-01) Broadcast data
728  template<class Container>
729  FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
730  static void mapCombineScatter
731  (
732  Container& values,
733  const int tag = UPstream::msgType(),
734  const int comm = UPstream::worldComm
735  )
736  {
737  Pstream::broadcast(values, comm);
738  }
739 
740  //- The inverse of gatherList, but when combined with gatherList
741  //- it effectively acts like a partial broadcast...
742  // \deprecated(2025-03) Normally prefer broadcast
743  template<class T>
744  FOAM_DEPRECATED_FOR(2025-03, "broadcast() or broadcastList()")
745  static void scatterList
746  (
748  UList<T>& values,
749  const int tag = UPstream::msgType(),
750  const int communicator = UPstream::worldComm
751  )
752  {
753  if (UPstream::is_parallel(communicator))
754  {
756  (
757  UPstream::whichCommunication(communicator),
758  values,
759  tag,
760  communicator
761  );
762  }
763  }
764 };
765 
766 
767 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
768 
769 } // End namespace Foam
770 
771 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
772 
773 #ifdef NoRepository
774  #include "PstreamBroadcast.txx"
775  #include "PstreamGather.txx"
776  #include "PstreamGatherList.txx"
777  #include "PstreamExchange.txx"
778 #endif
779 
780 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
781 
782 #endif
783 
784 // ************************************************************************* //
static bool gatherList_topo_algorithm(UList< T > &values, const int tag, const int communicator)
Gather data, keeping individual values separate.
static void listCombineAllGather(UList< T > &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Same as Pstream::listCombineReduce.
Definition: Pstream.H:391
static void exchangeSizes(const labelUList &sendProcs, const labelUList &recvProcs, const Container &sendBufs, labelList &sizes, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Helper: exchange sizes of sendBufs for specified send/recv ranks.
static void exchangeConsensus(const UList< Container > &sendBufs, List< Container > &recvBufs, const int tag, const int comm, const bool wait=true)
Exchange contiguous data using non-blocking consensus (NBX) Sends sendData, receives into recvData...
static void scatter(T &value, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Definition: Pstream.H:805
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:107
commsTypes
Communications types.
Definition: UPstream.H:77
static void broadcasts(const int communicator, Type &value, Args &&... values)
Broadcast multiple items to all communicator ranks. Does nothing in non-parallel. ...
static bool gather_topo_algorithm(T &value, BinaryOp bop, const int tag, const int communicator)
Implementation: gather (reduce) single element data onto UPstream::masterNo() using a topo algorithm...
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
static void combineScatter(T &value, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Definition: Pstream.H:820
static void mapGather(Container &values, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Gather (reduce) Map/HashTable containers, applying bop to combine entries from different processors...
FOAM_DEPRECATED_FOR(2025-03, "broadcast() or broadcastList()") static void scatterList(UList< T > &values
The inverse of gatherList, but when combined with gatherList it effectively acts like a partial broad...
static void combineAllGather(T &value, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Same as Pstream::combineReduce.
Definition: Pstream.H:279
void setCapacity(const label len)
Alter the size of the underlying storage.
Definition: DynamicListI.H:308
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1787
static void gather_algorithm(const UPstream::commsStructList &comms, T &value, BinaryOp bop, const int tag, const int communicator)
Implementation: gather (reduce) single element data onto UPstream::masterNo()
static void broadcast(Type &value, const int communicator=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
static T listScatterValues(const UList< T > &allValues, const int communicator=UPstream::worldComm, const int tag=UPstream::msgType())
Scatter individual values from list locations.
const int tag
Definition: Pstream.H:871
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition: UPstream.H:987
static void scatterList_algorithm(const UPstream::commsStructList &comms, UList< T > &values, const int tag, const int communicator)
Implementation: inverse of gatherList_algorithm.
static void combineGather(T &value, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Forwards to Pstream::gather with an in-place cop.
static void gatherList(UList< T > &values, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Gather data, but keep individual values separate.
static void broadcastList(ListType &list, const int communicator=UPstream::worldComm)
Broadcast list content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-...
static void exchange(const UList< Container > &sendBufs, const labelUList &recvSizes, List< Container > &recvBufs, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm, const bool wait=true)
Helper: exchange contiguous data. Sends sendBufs, receives into recvBufs using predetermined receive ...
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
static void listGather(UList< T > &values, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Gather (reduce) list elements, applying bop to each list element.
static const commsStructList & whichCommunication(const int communicator, bool linear=false)
Communication schedule for all-to-master (proc 0) as linear/tree/none with switching based on UPstrea...
Definition: UPstream.H:1760
Inter-processor communications stream.
Definition: Pstream.H:53
static void mapCombineReduce(Container &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Forwards to Pstream::mapReduce with an in-place cop.
static bool mapGather_topo_algorithm(Container &values, BinaryOp bop, const int tag, const int communicator)
Implementation: gather (reduce) Map/HashTable containers onto UPstream::masterNo() using a topo algor...
static void listCombineScatter(List< T > &value, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Definition: Pstream.H:835
static bool is_parallel(const label communicator=worldComm)
True if parallel algorithm or exchange is required.
Definition: UPstream.H:1648
static void mapCombineGather(Container &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Forwards to Pstream::mapGather with an in-place cop.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:1819
const direction noexcept
Definition: scalarImpl.H:255
UPstream(const commsTypes commsType) noexcept
Construct for given communication type.
Definition: UPstream.H:1102
static void listGather_algorithm(const UPstream::commsStructList &comms, UList< T > &values, BinaryOp bop, const int tag, const int communicator)
Implementation: gather (reduce) list element data onto UPstream::masterNo()
Collection of communication structures.
Definition: UPstream.H:354
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
Definition: UPstream.H:2237
ClassName("Pstream")
Declare name of the class and its debug switch.
static void allGatherList(UList< T > &values, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Gather data, but keep individual values separate. Uses MPI_Allgather or manual communication.
static void gatherList_algorithm(const UPstream::commsStructList &comms, UList< T > &values, const int tag, const int communicator)
Implementation: gather data, keeping individual values separate. Output is only valid (consistent) on...
static void mapCombineScatter(Container &values, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Definition: Pstream.H:850
static void combineReduce(T &value, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors...
static void listCombineReduce(UList< T > &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Forwards to Pstream::listReduce with an in-place cop.
static void mapReduce(Container &values, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying bop to combine map values from different processors...
static List< T > listGatherValues(const T &localValue, const int communicator=UPstream::worldComm, const int tag=UPstream::msgType())
Gather individual values into list locations.
DynamicList< char > transferBuf_
Allocated transfer buffer (can be used for send or receive)
Definition: Pstream.H:64
static void gather(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Gather (reduce) data, applying bop to combine value from different processors. The basis for Foam::re...
static void listReduce(UList< T > &values, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce list elements (list must be equal size on all ranks), applying bop to each list element...
static void mapGather_algorithm(const UPstream::commsStructList &comms, Container &values, BinaryOp bop, const int tag, const int communicator)
Implementation: gather (reduce) Map/HashTable containers onto UPstream::masterNo() ...
Inter-processor communications stream.
Definition: UPstream.H:65
static void listCombineGather(UList< T > &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Forwards to Pstream::listGather with an in-place cop.
static bool broadcast(Type *buffer, std::streamsize count, const int communicator)
Broadcast buffer contents (contiguous types), from rank=0 to all ranks. The sizes must match on all p...
Pstream(const UPstream::commsTypes commsType) noexcept
Construct for communication type with empty buffer.
Definition: Pstream.H:80
Namespace for OpenFOAM.
static bool listGather_topo_algorithm(UList< T > &values, BinaryOp bop, const int tag, const int communicator)
Implementation: gather (reduce) list element data onto UPstream::masterNo() using a topo algorithm...
static void mapCombineAllGather(Container &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Same as Pstream::mapCombineReduce.
Definition: Pstream.H:502
A HashTable to objects of type <T> with a label key.