Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::Pstream
29
30Description
31 Inter-processor communications stream.
32
33SourceFiles
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
51namespace Foam
52{
53
54// Forward Declarations
55class bitSet;
57/*---------------------------------------------------------------------------*\
58 Class Pstream Declaration
59\*---------------------------------------------------------------------------*/
60
61class Pstream
62:
63 public UPstream
64{
65protected:
66
67 // Protected Data
68
69 //- Allocated transfer buffer (can be used for send or receive)
71
72
73public:
74
75 //- Declare name of the class and its debug switch
76 ClassName("Pstream");
77
78
79 // Constructors
80
81 //- Construct for communication type with empty buffer
83 :
85 {}
86
87 //- Construct for communication type with given buffer size
88 Pstream(const UPstream::commsTypes commsType, int bufferSize)
89 :
91 {
92 if (bufferSize > 0)
93 {
94 transferBuf_.setCapacity(bufferSize + 2*sizeof(scalar) + 1);
95 }
96 }
97
98
99 // Static Functions
100
101 // Broadcast
102
103 //- Broadcast buffer content to all processes in communicator.
105
106 //- Broadcast content (contiguous or non-contiguous) to all
107 //- communicator ranks. Does nothing in \b non-parallel.
108 template<class Type>
109 static void broadcast
110 (
111 Type& value,
112 const int communicator = UPstream::worldComm
113 );
114
115 //- Broadcast fixed-list content (contiguous or non-contiguous) to all
116 //- communicator ranks. Does nothing in \b non-parallel.
117 template<class Type, unsigned N>
118 static void broadcast
119 (
120 FixedList<Type, N>& list,
122 );
123
124 //- Broadcast multiple items to all communicator ranks.
125 //- Does nothing in \b non-parallel.
126 template<class Type, class... Args>
127 static void broadcasts
128 (
129 const int communicator,
130 Type& value,
131 Args&&... values
132 );
133
134 //- Broadcast list content (contiguous or non-contiguous) to all
135 //- communicator ranks. Does nothing in \b non-parallel.
136 // For contiguous list data, this avoids serialization overhead,
137 // but at the expense of an additional broadcast call.
138 template<class ListType>
139 static void broadcastList
140 (
141 ListType& list,
143 );
144
145
146 // Gather/scatter : single value
147
148 //- Implementation: gather (reduce) single element data onto
149 //- UPstream::masterNo()
150 template<class T, class BinaryOp, bool InplaceMode>
151 static void gather_algorithm
152 (
155 T& value,
156 BinaryOp bop,
157 const int tag,
158 const int communicator
159 );
160
161 //- Implementation: gather (reduce) single element data onto
162 //- UPstream::masterNo() using a topo algorithm.
163 // \returns True if topo algorithm was applied
164 template<class T, class BinaryOp, bool InplaceMode>
165 static bool gather_topo_algorithm
166 (
168 T& value,
169 BinaryOp bop,
170 const int tag,
171 const int communicator
172 );
173
174 //- Gather (reduce) data, applying \c bop to combine \c value
175 //- from different processors. The basis for Foam::reduce().
176 // A no-op for non-parallel.
177 //
178 // \tparam InplaceMode indicates that the binary operator
179 // modifies values in-place, not using assignment
180 template<class T, class BinaryOp, bool InplaceMode=false>
181 static void gather
182 (
184 T& value,
185 BinaryOp bop,
186 const int tag = UPstream::msgType(),
188 );
189
190 //- Gather individual values into list locations.
191 // On master list length == nProcs, otherwise zero length.
192 // \n
193 // For \b non-parallel :
194 // the returned list length is 1 with localValue.
195 template<class T>
197 (
198 const T& localValue,
201 const int tag = UPstream::msgType()
202 );
204 //- Scatter individual values from list locations.
205 // On master input list length == nProcs, ignored on other procs.
206 // \n
207 // For \b non-parallel :
208 // returns the first list element (or default initialized).
209 template<class T>
210 static T listScatterValues
211 (
212 const UList<T>& allValues,
215 const int tag = UPstream::msgType()
216 );
217
218
219 // Inplace combine (gather) : single value
220
221 //- Forwards to Pstream::gather with an \em in-place \c cop
222 template<class T, class CombineOp>
223 static void combineGather
224 (
226 T& value,
227 CombineOp cop,
228 const int tag = UPstream::msgType(),
230 );
231
232 //- Reduce inplace (cf. MPI Allreduce)
233 //- applying \c cop to inplace combine \c value
234 //- from different processors.
235 template<class T, class CombineOp>
236 static void combineReduce
237 (
239 T& value,
240 CombineOp cop,
241 const int tag = UPstream::msgType(),
243 );
244
245 //- Same as Pstream::combineReduce
246 template<class T, class CombineOp>
247 static void combineAllGather
248 (
250 T& value,
251 CombineOp cop,
252 const int tag = UPstream::msgType(),
254 )
255 {
257 }
258
259
260 // Gather/combine variants working on entire List
261
262 //- Implementation: gather (reduce) list element data onto
263 //- UPstream::masterNo()
264 template<class T, class BinaryOp, bool InplaceMode>
265 static void listGather_algorithm
266 (
267 const UPstream::commsStructList& comms,
269 UList<T>& values,
270 BinaryOp bop,
271 const int tag,
272 const int communicator
273 );
274
275 //- Implementation: gather (reduce) list element data onto
276 //- UPstream::masterNo() using a topo algorithm.
277 // \returns True if topo algorithm was applied
278 template<class T, class BinaryOp, bool InplaceMode>
279 static bool listGather_topo_algorithm
280 (
281 //! [in,out]
282 UList<T>& values,
283 BinaryOp bop,
284 const int tag,
285 const int communicator
286 );
287
288 //- Gather (reduce) list elements,
289 //- applying \c bop to each list element
290 //
291 // \tparam InplaceMode indicates that the binary operator
292 // modifies values in-place, not using assignment
293 template<class T, class BinaryOp, bool InplaceMode=false>
294 static void listGather
295 (
297 UList<T>& values,
298 BinaryOp bop,
299 const int tag = UPstream::msgType(),
301 );
302
303 //- Forwards to Pstream::listGather with an \em in-place \c cop
304 template<class T, class CombineOp>
305 static void listCombineGather
306 (
308 UList<T>& values,
309 CombineOp cop,
310 const int tag = UPstream::msgType(),
312 );
313
314 //- Reduce list elements (list must be equal size on all ranks),
315 //- applying \c bop to each list element.
316 //
317 // \tparam InplaceMode indicates that the binary operator
318 // modifies values in-place, not using assignment
319 template<class T, class BinaryOp, bool InplaceMode=false>
320 static void listReduce
321 (
323 UList<T>& values,
324 BinaryOp bop,
325 const int tag = UPstream::msgType(),
327 );
328
329 //- Forwards to Pstream::listReduce with an \em in-place \c cop
330 template<class T, class CombineOp>
331 static void listCombineReduce
332 (
334 UList<T>& values,
335 CombineOp cop,
336 const int tag = UPstream::msgType(),
338 );
339
340 //- Same as Pstream::listCombineReduce
341 template<class T, class CombineOp>
342 static void listCombineAllGather
343 (
345 UList<T>& values,
346 CombineOp cop,
347 const int tag = UPstream::msgType(),
350 {
352 }
353
354
355 // Gather/combine variants working on Map/HashTable containers
356
357 //- Implementation: gather (reduce) Map/HashTable containers onto
358 //- UPstream::masterNo()
359 template<class Container, class BinaryOp, bool InplaceMode>
360 static void mapGather_algorithm
361 (
362 const UPstream::commsStructList& comms,
363 Container& values,
364 BinaryOp bop,
365 const int tag,
366 const int communicator
367 );
368
369 //- Implementation: gather (reduce) Map/HashTable containers onto
370 //- UPstream::masterNo() using a topo algorithm.
371 // \returns True if topo algorithm was applied
372 template<class Container, class BinaryOp, bool InplaceMode>
373 static bool mapGather_topo_algorithm
374 (
375 Container& values,
376 BinaryOp bop,
377 const int tag,
378 const int communicator
379 );
381 //- Gather (reduce) Map/HashTable containers,
382 //- applying \c bop to combine entries from different processors.
383 //
384 // \tparam InplaceMode indicates that the binary operator
385 // modifies values in-place, not using assignment
386 template<class Container, class BinaryOp, bool InplaceMode=false>
387 static void mapGather
388 (
390 Container& values,
391 BinaryOp bop,
392 const int tag = UPstream::msgType(),
394 );
395
396 //- Forwards to Pstream::mapGather with an \em in-place \c cop
397 template<class Container, class CombineOp>
398 static void mapCombineGather
399 (
401 Container& values,
402 CombineOp cop,
403 const int tag = UPstream::msgType(),
405 );
406
407 //- Reduce inplace (cf. MPI Allreduce)
408 //- applying \c bop to combine map \c values
409 //- from different processors.
410 //- After completion all processors have the same data.
411 //
412 // Wraps mapCombineGather/broadcast (may change in the future).
413 template<class Container, class BinaryOp, bool InplaceMode=false>
414 static void mapReduce
415 (
417 Container& values,
418 BinaryOp bop,
419 const int tag = UPstream::msgType(),
421 );
422
423 //- Forwards to Pstream::mapReduce with an \em in-place \c cop
424 template<class Container, class CombineOp>
425 static void mapCombineReduce
426 (
428 Container& values,
429 CombineOp cop,
430 const int tag = UPstream::msgType(),
432 );
433
434 //- Same as Pstream::mapCombineReduce
435 template<class Container, class CombineOp>
436 static void mapCombineAllGather
437 (
439 Container& values,
440 CombineOp cop,
441 const int tag = UPstream::msgType(),
443 )
444 {
447
448
449 // Gather/scatter keeping the individual processor data separate.
450 // The values is a List of size UPstream::nProcs() where
451 // values[UPstream::myProcNo()] is the data for the current processor.
452
453 //- Implementation: gather data, keeping individual values separate.
454 //- Output is only valid (consistent) on UPstream::masterNo()
455 template<class T>
456 static void gatherList_algorithm
457 (
458 const UPstream::commsStructList& comms,
460 UList<T>& values,
461 const int tag,
462 const int communicator
463 );
464
465 //- Gather data, keeping individual values separate.
466 // \returns True if topo algorithm was applied
467 template<class T>
468 static bool gatherList_topo_algorithm
469 (
471 UList<T>& values,
472 const int tag,
473 const int communicator
474 );
475
476 //- Implementation: inverse of gatherList_algorithm
477 template<class T>
479 (
480 const UPstream::commsStructList& comms,
482 UList<T>& values,
483 const int tag,
484 const int communicator
485 );
486
487 //- Gather data, but keep individual values separate.
488 template<class T>
489 static void gatherList
490 (
492 UList<T>& values,
493 const int tag = UPstream::msgType(),
495 );
496
497 //- Gather data, but keep individual values separate.
498 //- Uses MPI_Allgather or manual communication.
499 // After completion all processors have the same data.
500 // Wraps gatherList/scatterList (may change in the future).
501 template<class T>
502 static void allGatherList
503 (
504 //! [in,out]
505 UList<T>& values,
506 const int tag = UPstream::msgType(),
508 );
509
510
511 // Exchange
512
513 //- Helper: exchange sizes of sendBufs for specified send/recv ranks
514 template<class Container>
515 static void exchangeSizes
516 (
517 const labelUList& sendProcs,
518 const labelUList& recvProcs,
519 const Container& sendBufs,
520 labelList& sizes,
521 const int tag = UPstream::msgType(),
522 const int comm = UPstream::worldComm
523 );
524
525 //- Helper: exchange sizes of sendBufs for specified neighbour ranks
526 template<class Container>
527 static void exchangeSizes
528 (
529 const labelUList& neighProcs,
530 const Container& sendBufs,
531 labelList& sizes,
532 const int tag = UPstream::msgType(),
533 const int comm = UPstream::worldComm
534 );
535
536 //- Helper: exchange sizes of sendBufs.
537 //- The sendBufs is the data per processor (in the communicator).
538 // Returns sizes of sendBufs on the sending processor.
539 // \n
540 // For \b non-parallel : copy sizes from sendBufs directly.
541 template<class Container>
542 static void exchangeSizes
543 (
544 const Container& sendBufs,
545 labelList& recvSizes,
546 const int comm = UPstream::worldComm
547 );
548
549 //- Exchange the \b non-zero sizes of sendBufs entries (sparse map)
550 //- with other ranks in the communicator
551 //- using non-blocking consensus exchange.
552 //
553 // Since the recvData map always cleared before receipt and sizes
554 // of zero are never transmitted, a simple check
555 // of its keys is sufficient to determine connectivity.
556 //
557 // For \b non-parallel : copy size of rank (if it exists and non-empty)
558 // from sendBufs to recvSizes.
559 //
560 // \note The message tag is adjusted internally to improve uniqueness
561 template<class Container>
562 static void exchangeSizes
563 (
564 const Map<Container>& sendBufs,
565 Map<label>& recvSizes,
566 const int tag = UPstream::msgType(),
567 const int comm = UPstream::worldComm
568 );
569
570 //- Helper: exchange \em contiguous data.
571 //- Sends sendBufs, receives into recvBufs using predetermined receive
572 //- sizing.
573 // If wait=true will wait for all transfers to finish.
574 template<class Container, class Type>
575 static void exchange
576 (
577 const UList<Container>& sendBufs,
578 const labelUList& recvSizes,
579 List<Container>& recvBufs,
580 const int tag = UPstream::msgType(),
581 const int comm = UPstream::worldComm,
582 const bool wait = true
583 );
584
585 //- Exchange \em contiguous data.
586 //- Sends sendBufs, receives into recvBufs.
587 // Data provided and received as container.
588 //
589 // No internal guards or resizing.
590 template<class Container, class Type>
591 static void exchange
592 (
593 const Map<Container>& sendBufs,
594 const Map<label>& recvSizes,
595 Map<Container>& recvBufs,
596 const int tag = UPstream::msgType(),
597 const int comm = UPstream::worldComm,
598 const bool wait = true
599 );
600
601 //- Exchange \em contiguous data.
602 //- Sends sendBufs, receives into recvBufs.
603 //- Determines sizes to receive.
604 // If wait=true will wait for all transfers to finish.
605 template<class Container, class Type>
606 static void exchange
607 (
608 const UList<Container>& sendBufs,
609 List<Container>& recvBufs,
610 const int tag = UPstream::msgType(),
611 const int comm = UPstream::worldComm,
612 const bool wait = true
613 );
614
615 //- Exchange \em contiguous data.
616 //- Sends sendBufs, receives into recvBufs.
617 //- Determines sizes to receive.
618 // If wait=true will wait for all transfers to finish.
619 template<class Container, class Type>
620 static void exchange
621 (
622 const Map<Container>& sendBufs,
623 Map<Container>& recvBufs,
624 const int tag = UPstream::msgType(),
625 const int comm = UPstream::worldComm,
626 const bool wait = true
627 );
628
630 // Non-blocking exchange
631
632 //- Exchange \em contiguous data using non-blocking consensus (NBX)
633 //- Sends sendData, receives into recvData.
634 //
635 // Each entry of the recvBufs list is cleared before receipt.
636 // For \b non-parallel : copy own rank from sendBufs to recvBufs.
637 //
638 // \note The message tag should be chosen to be a unique value
639 // since the implementation uses probing with ANY_SOURCE !!
640 template<class Container, class Type>
641 static void exchangeConsensus
642 (
643 const UList<Container>& sendBufs,
644 List<Container>& recvBufs,
645 const int tag,
646 const int comm,
647 const bool wait = true
648 );
649
650 //- Exchange \em contiguous data using non-blocking consensus (NBX)
651 //- Sends sendData, receives into recvData.
652 //
653 // Each \em entry of the recvBufs map is cleared before receipt,
654 // but the map itself if not cleared. This allows the map to preserve
655 // allocated space (eg DynamicList entries) between calls.
656 //
657 // For \b non-parallel : copy own rank (if it exists and non-empty)
658 // from sendBufs to recvBufs.
659 //
660 // \note The message tag should be chosen to be a unique value
661 // since the implementation uses probing with ANY_SOURCE !!
662 template<class Container, class Type>
663 static void exchangeConsensus
664 (
665 const Map<Container>& sendBufs,
666 Map<Container>& recvBufs,
667 const int tag,
668 const int comm,
669 const bool wait = true
670 );
671
672 //- Exchange \em contiguous data using non-blocking consensus (NBX)
673 //- Sends sendData returns receive information.
674 //
675 // For \b non-parallel : copy own rank (if it exists and non-empty)
676 //
677 // \note The message tag should be chosen to be a unique value
678 // since the implementation uses probing with ANY_SOURCE !!
679 template<class Container, class Type>
681 (
682 const Map<Container>& sendBufs,
683 const int tag,
684 const int comm,
685 const bool wait = true
686 );
688
689 // Housekeeping
690
691 //- \deprecated(2024-01) Broadcast data
692 template<class T>
693 FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
694 static void scatter
695 (
696 T& value,
697 const int tag = UPstream::msgType(),
698 const int comm = UPstream::worldComm
699 )
700 {
701 Pstream::broadcast(value, comm);
702 }
703
704 //- \deprecated(2024-01) Broadcast data
705 template<class T>
706 FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
707 static void combineScatter
708 (
709 T& value,
710 const int tag = UPstream::msgType(),
711 const int comm = UPstream::worldComm
712 )
713 {
714 Pstream::broadcast(value, comm);
715 }
716
717 //- \deprecated(2024-01) Broadcast data
718 template<class T>
719 FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
720 static void listCombineScatter
721 (
722 List<T>& value,
723 const int tag = UPstream::msgType(),
724 const int comm = UPstream::worldComm
725 )
726 {
727 Pstream::broadcast(value, comm);
728 }
729
730 //- \deprecated(2024-01) Broadcast data
731 template<class Container>
732 FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
733 static void mapCombineScatter
734 (
735 Container& values,
736 const int tag = UPstream::msgType(),
737 const int comm = UPstream::worldComm
738 )
739 {
740 Pstream::broadcast(values, comm);
741 }
742
743 //- The inverse of gatherList, but when combined with gatherList
744 //- it effectively acts like a partial broadcast...
745 // \deprecated(2025-03) Normally prefer broadcast
746 template<class T>
747 FOAM_DEPRECATED_FOR(2025-03, "broadcast() or broadcastList()")
748 static void scatterList
749 (
751 UList<T>& values,
752 const int tag = UPstream::msgType(),
753 const int communicator = UPstream::worldComm
754 )
755 {
757 {
759 (
761 values,
762 tag,
764 );
765 }
766 }
767};
768
769
770// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
772} // End namespace Foam
773
774// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
775
776#ifdef NoRepository
777 #include "PstreamBroadcast.txx"
778 #include "PstreamGather.txx"
779 #include "PstreamGatherList.txx"
780 #include "PstreamExchange.txx"
781#endif
782
783// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
784
785#endif
786
787// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
A 1D vector of objects of type <T> with a fixed length <N>.
Definition FixedList.H:73
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
static void exchangeSizes(const labelUList &neighProcs, const Container &sendBufs, labelList &sizes, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Helper: exchange sizes of sendBufs for specified neighbour ranks.
DynamicList< char > transferBuf_
Allocated transfer buffer (can be used for send or receive).
Definition Pstream.H:67
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 bool gatherList_topo_algorithm(UList< T > &values, const int tag, const int communicator)
Gather data, keeping individual values separate.
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 ...
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 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 exchangeConsensus(const Map< Container > &sendBufs, Map< 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 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 listCombineAllGather(UList< T > &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Same as Pstream::listCombineReduce.
Definition Pstream.H:394
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.
ClassName("Pstream")
Declare name of the class and its debug switch.
static List< T > listGatherValues(const T &localValue, const int communicator=UPstream::worldComm, const int tag=UPstream::msgType())
Gather individual values into list locations.
static void listCombineScatter(List< T > &value, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Definition Pstream.H:838
Pstream(const UPstream::commsTypes commsType, int bufferSize)
Construct for communication type with given buffer size.
Definition Pstream.H:91
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 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 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 mapCombineGather(Container &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Forwards to Pstream::mapGather with an in-place cop.
static Map< Container > exchangeConsensus(const Map< Container > &sendBufs, const int tag, const int comm, const bool wait=true)
Exchange contiguous data using non-blocking consensus (NBX) Sends sendData returns receive informatio...
Pstream(const UPstream::commsTypes commsType) noexcept
Construct for communication type with empty buffer.
Definition Pstream.H:83
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 broadcast(Type &value, const int communicator=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
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.
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 exchange(const Map< Container > &sendBufs, const Map< label > &recvSizes, Map< Container > &recvBufs, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm, const bool wait=true)
Exchange contiguous data. Sends sendBufs, receives into recvBufs.
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 broadcast(FixedList< Type, N > &list, const int communicator=UPstream::worldComm)
Broadcast fixed-list content (contiguous or non-contiguous) to all communicator ranks....
static void mapCombineAllGather(Container &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Same as Pstream::mapCombineReduce.
Definition Pstream.H:505
static void combineScatter(T &value, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Definition Pstream.H:823
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, List< Container > &recvBufs, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm, const bool wait=true)
Exchange contiguous data. Sends sendBufs, receives into recvBufs. Determines sizes to receive.
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 T listScatterValues(const UList< T > &allValues, const int communicator=UPstream::worldComm, const int tag=UPstream::msgType())
Scatter individual values from list locations.
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().
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.
static void combineAllGather(T &value, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Same as Pstream::combineReduce.
Definition Pstream.H:282
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 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().
static void exchangeSizes(const Map< Container > &sendBufs, Map< label > &recvSizes, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Exchange the non-zero sizes of sendBufs entries (sparse map) with other ranks in the communicator usi...
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 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 void scatterList_algorithm(const UPstream::commsStructList &comms, UList< T > &values, const int tag, const int communicator)
Implementation: inverse of gatherList_algorithm.
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().
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 exchange(const Map< Container > &sendBufs, Map< Container > &recvBufs, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm, const bool wait=true)
Exchange contiguous data. Sends sendBufs, receives into recvBufs. Determines sizes to receive.
const int tag
Definition Pstream.H:874
static void exchangeSizes(const Container &sendBufs, labelList &recvSizes, const int comm=UPstream::worldComm)
Helper: exchange sizes of sendBufs. The sendBufs is the data per processor (in the communicator).
static void mapCombineScatter(Container &values, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Definition Pstream.H:853
static void broadcasts(const int communicator, Type &value, Args &&... values)
Broadcast multiple items to all communicator ranks. Does nothing in non-parallel.
static void scatter(T &value, const int tag=UPstream::msgType(), const int comm=UPstream::worldComm)
Definition Pstream.H:808
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
Collection of communication structures.
Definition UPstream.H:363
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
Definition UPstream.H:2546
Inter-processor communications stream.
Definition UPstream.H:69
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:1899
commsTypes
Communications types.
Definition UPstream.H:81
static int & msgType() noexcept
Message tag of standard messages.
Definition UPstream.H:1926
static bool broadcast(Type *buffer, std::streamsize count, const int communicator, const int root=UPstream::masterNo())
Broadcast buffer contents (contiguous types) to all ranks (default: from rank=0). The sizes must matc...
static bool is_parallel(const label communicator=worldComm)
True if parallel algorithm or exchange is required.
Definition UPstream.H:1743
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition UPstream.H:1958
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition UPstream.H:1069
UPstream(const commsTypes commsType) noexcept
Construct for given communication type.
Definition UPstream.H:1184
@ broadcast
broadcast [MPI]
Definition UPstream.H:189
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
const direction noexcept
Definition scalarImpl.H:265
UList< label > labelUList
A UList of labels.
Definition UList.H:75
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition stdFoam.H:43