UPstream.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-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2022 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::UPstream
29 
30 Description
31  Inter-processor communications stream
32 
33 SourceFiles
34  UPstream.C
35  UPstreamCommsStruct.C
36  UPstreamTemplates.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Foam_UPstream_H
41 #define Foam_UPstream_H
42 
43 #include "labelList.H"
44 #include "DynamicList.H"
45 #include "HashTable.H"
46 #include "string.H"
47 #include "Enum.H"
48 #include "ListOps.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class UPstream Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class UPstream
60 {
61 public:
62 
63  //- Int ranges are used for MPI ranks (processes)
64  typedef IntRange<int> rangeType;
65 
66  //- Types of communications
67  enum class commsTypes : char
68  {
69  blocking,
70  scheduled,
72  };
73 
74  //- Enumerated names for the communication types
75  static const Enum<commsTypes> commsTypeNames;
76 
77 
78  // Public Classes
79 
80  //- Structure for communicating between processors
81  class commsStruct
82  {
83  // Private Data
84 
85  //- The procID of the processor directly above
86  label above_;
87 
88  //- The procIDs of all processors directly below
89  labelList below_;
90 
91  //- procIDs of all processors below (so not just directly below)
92  labelList allBelow_;
93 
94  //- procIDs of all processors not below.
95  // Inverse set of allBelow_ without myProcNo.
96  labelList allNotBelow_;
97 
98 
99  public:
100 
101  // Constructors
102 
103  //- Default construct. Above == -1
105 
106  //- Construct from components
108  (
109  const label above,
110  const labelUList& below,
111  const labelUList& allBelow,
112  const labelUList& allNotBelow
113  );
114 
115  //- Construct from components; construct allNotBelow_
117  (
118  const label nProcs,
119  const label myProcID,
120  const label above,
121  const labelUList& below,
122  const labelUList& allBelow
123  );
124 
125 
126  // Member Functions
127 
128  //- Reset to default constructed state
129  void clear();
130 
131  //- The procID of the processor directly above
132  label above() const noexcept
133  {
134  return above_;
135  }
136 
137  //- The procIDs of all processors directly below
138  const labelList& below() const noexcept
139  {
140  return below_;
141  }
142 
143  //- The procIDs of all processors below
144  //- (so not just directly below)
145  const labelList& allBelow() const noexcept
146  {
147  return allBelow_;
148  }
149 
150  //- The procIDs of all processors that are above.
151  //- The inverse set of allBelow without myProcNo.
152  const labelList& allNotBelow() const noexcept
153  {
154  return allNotBelow_;
155  }
156 
157 
158  // Member Operators
159 
160  bool operator==(const commsStruct&) const;
161  bool operator!=(const commsStruct&) const;
163 
164  // Ostream Operator
165 
166  friend Ostream& operator<<(Ostream&, const commsStruct&);
167  };
168 
169 
170  //- combineReduce operator for lists. Used for counting.
171  struct listEq
172  {
173  template<class T>
174  void operator()(T& x, const T& y) const
175  {
176  forAll(y, i)
177  {
178  if (y[i].size())
179  {
180  x[i] = y[i];
181  }
182  }
183  }
184  };
185 
186 
187 private:
188 
189  // Private Data
190 
191  //- Communications type of this stream
192  commsTypes commsType_;
193 
194 
195  // Private Static Data
196 
197  //- By default this is not a parallel run
198  static bool parRun_;
199 
200  //- Have support for threads?
201  static bool haveThreads_;
202 
203  //- Standard transfer message type
204  static int msgType_;
205 
206  //- Names of all worlds
207  static wordList allWorlds_;
208 
209  //- Per processor the world index (into allWorlds_)
210  static labelList worldIDs_;
211 
212 
213  // Communicator specific data
214 
215  //- My processor number
216  static DynamicList<int> myProcNo_;
217 
218  //- List of process IDs
219  static DynamicList<List<int>> procIDs_;
220 
221  //- Parent communicator
222  static DynamicList<label> parentComm_;
223 
224  //- Free communicators
225  static DynamicList<label> freeComms_;
226 
227  //- Linear communication schedule
228  static DynamicList<List<commsStruct>> linearCommunication_;
229 
230  //- Multi level communication schedule
231  static DynamicList<List<commsStruct>> treeCommunication_;
232 
233 
234  // Private Member Functions
235 
236  //- Set data for parallel running
237  static void setParRun(const label nProcs, const bool haveThreads);
238 
239  //- Allocate a communicator with index
240  static void allocatePstreamCommunicator
241  (
242  const label parentIndex,
243  const label index
244  );
245 
246  //- Free MPI components of communicator.
247  // Does not touch the first two communicators (SELF, WORLD)
248  static void freePstreamCommunicator(const label index);
249 
250 
251 public:
252 
253  //- Declare name of the class and its debug switch
254  ClassName("UPstream");
255 
256 
257  // Static Data
258 
259  //- Should compact transfer be used in which floats replace doubles
260  //- reducing the bandwidth requirement at the expense of some loss
261  //- in accuracy
262  static bool floatTransfer;
263 
264  //- Number of processors to change from linear to tree communication
265  static int nProcsSimpleSum;
266 
267  //- Default commsType
269 
270  //- Number of polling cycles in processor updates
271  static int nPollProcInterfaces;
272 
273  //- Optional maximum message size (bytes)
274  static int maxCommsSize;
275 
276  //- MPI buffer-size (bytes)
277  static const int mpiBufferSize;
278 
279 
280  // Standard Communicators
281 
282  //- Default world communicator (all processors).
283  //- May differ from globalComm if local worlds are in use
284  static label worldComm;
285 
286  //- Debugging: warn for use of any communicator differing from warnComm
287  static label warnComm;
288 
289  //- Communicator for all processors, irrespective of any local worlds
290  static constexpr label globalComm = 0;
291 
292  //- A communicator within the current rank only
293  static constexpr label selfComm = 1;
294 
295  //- Number of currently defined communicators
296  static label nComms() noexcept { return parentComm_.size(); }
297 
298  //- True if communicator appears to be user-allocated
299  static bool isUserComm(label communicator) noexcept
300  {
302  }
303 
304 
305  // Constructors
306 
307  //- Construct for given communication type
308  explicit UPstream(const commsTypes commsType)
309  :
310  commsType_(commsType)
311  {}
312 
313 
314  // Member Functions
315 
316  //- Allocate a new communicator with subRanks of parent communicator
317  static label allocateCommunicator
318  (
320  const label parent,
321 
323  const labelUList& subRanks,
324 
326  const bool doPstream = true
327  );
328 
329  //- Free a previously allocated communicator.
330  // Ignores placeholder (negative) communicators.
331  static void freeCommunicator
332  (
333  const label communicator,
334  const bool doPstream = true
335  );
336 
337  //- Free all communicators
338  static void freeCommunicators(const bool doPstream);
339 
340 
341  //- Wrapper class for allocating/freeing communicators
343  {
344  label comm_;
345 
346  public:
348  //- No copy construct
349  communicator(const communicator&) = delete;
350 
351  //- No copy assignment
352  void operator=(const communicator&) = delete;
353 
354  //- Default construct (a placeholder communicator)
355  communicator() noexcept : comm_(-1) {}
356 
357  //- Move construct, takes ownership
358  communicator(communicator&& c) : comm_(c.comm_) { c.comm_ = -1; }
359 
360  //- Allocate a communicator based on given parent
362  (
364  const label parent,
365 
367  const labelUList& subRanks,
368 
370  const bool doPstream = true
371  )
372  :
373  comm_(allocateCommunicator(parent, subRanks, doPstream))
374  {}
375 
376  //- Free allocated communicator and group
377  ~communicator() { freeCommunicator(comm_); }
378 
379  //- True if communicator is non-negative (ie, was allocated)
380  bool good() const noexcept { return (comm_ >= 0); }
382  //- The communicator label
383  label comm() const noexcept { return comm_; }
384 
385  //- Free allocated communicator and group
386  void reset() { freeCommunicator(comm_); comm_ = -1; }
387 
388  //- Allocate with subRanks of parent communicator
389  void reset(label parent, const labelUList& subRanks)
390  {
391  freeCommunicator(comm_);
392  comm_ = allocateCommunicator(parent, subRanks);
393  }
394 
395  //- Take ownership, free allocated communicator and group.
396  void reset(communicator&& c)
397  {
398  if (comm_ != c.comm_) freeCommunicator(comm_);
399  comm_ = c.comm_;
400  c.comm_ = -1;
401  }
402 
403  //- Move assignment, takes ownership
404  void operator=(communicator&& c) { reset(std::move(c)); }
405 
406  //- Cast to label - the same as comm()
407  operator label() const noexcept { return comm_; }
408  };
409 
410 
411  //- Return physical processor number (i.e. processor number in
412  //- worldComm) given communicator and processor
413  static int baseProcNo(label comm, int procID);
414 
415  //- Return processor number in communicator (given physical processor
416  //- number) (= reverse of baseProcNo)
417  static label procNo(const label comm, const int baseProcID);
418 
419  //- Return processor number in communicator (given processor number
420  //- and communicator)
421  static label procNo
422  (
423  const label comm,
424  const label currentComm,
425  const int currentProcID
426  );
427 
428  //- Add the valid option this type of communications library
429  //- adds/requires on the command line
430  static void addValidParOptions(HashTable<string>& validParOptions);
431 
432  //- Initialisation function called from main
433  // Spawns sub-processes and initialises inter-communication
434  static bool init(int& argc, char**& argv, const bool needsThread);
435 
436  //- Special purpose initialisation function.
437  // Performs a basic MPI_Init without any other setup.
438  // Only used for applications that need MPI communication when
439  // OpenFOAM is running in a non-parallel mode.
440  // \note Behaves as a no-op if MPI has already been initialized.
441  // Fatal if MPI has already been finalized.
442  static bool initNull();
443 
444 
445  // Non-blocking comms
446 
447  //- Number of outstanding requests
448  static label nRequests() noexcept;
449 
450  //- Truncate outstanding requests to given length
451  static void resetRequests(const label n);
452 
453  //- Wait until all requests (from start onwards) have finished.
454  // A no-op if parRun() == false
455  static void waitRequests(const label start = 0);
456 
457  //- Wait until request i has finished.
458  // A no-op if parRun() == false
459  // or for placeholder (negative) request indices
460  static void waitRequest(const label i);
461 
462  //- Non-blocking comms: has request i finished?
463  // A no-op and returns true if parRun() == false
464  // or for placeholder (negative) request indices
465  static bool finishedRequest(const label i);
466 
467  static int allocateTag(const char* const msg = nullptr);
468  static void freeTag(const int tag, const char* const msg = nullptr);
469 
471  //- Set as parallel run on/off.
472  // \return the previous value
473  static bool parRun(const bool on) noexcept
474  {
475  bool old(parRun_);
476  parRun_ = on;
477  return old;
478  }
479 
480  //- Test if this a parallel run
481  // Modify access is deprecated
482  static bool& parRun() noexcept
483  {
484  return parRun_;
485  }
486 
487  //- Have support for threads
488  static bool haveThreads() noexcept
489  {
490  return haveThreads_;
491  }
493  //- Number of ranks in parallel run (for given communicator)
494  //- is 1 for serial run
495  static label nProcs(const label communicator = worldComm)
496  {
497  return procIDs_[communicator].size();
498  }
499 
500  //- Process index of the master (always 0)
501  static constexpr int masterNo() noexcept
502  {
503  return 0;
504  }
505 
506  //- Am I the master rank
507  static bool master(const label communicator = worldComm)
508  {
509  return myProcNo_[communicator] == masterNo();
510  }
511 
512  //- Is this process a sub-rank on the communicator
513  static bool is_subrank(const label communicator = worldComm)
514  {
515  return myProcNo_[communicator] > masterNo();
516  }
517 
518  //- Number of this process (starting from masterNo() = 0)
519  static int myProcNo(const label communicator = worldComm)
520  {
521  return myProcNo_[communicator];
522  }
523 
524  //- The parent communicator
525  static label parent(const label communicator)
526  {
527  return parentComm_(communicator);
528  }
529 
530  //- Process IDs within a given communicator
531  static List<int>& procID(const label communicator)
532  {
533  return procIDs_[communicator];
534  }
535 
536 
537  // Worlds
538 
539  //- All worlds
540  static const wordList& allWorlds() noexcept
541  {
542  return allWorlds_;
543  }
544 
545  //- The indices into allWorlds for all processes
546  static const labelList& worldIDs() noexcept
547  {
548  return worldIDs_;
549  }
550 
551  //- My worldID
552  static label myWorldID()
553  {
554  return worldIDs_[myProcNo(globalComm)];
555  }
556 
557  //- My world
558  static const word& myWorld()
559  {
560  return allWorlds_[worldIDs_[myProcNo(globalComm)]];
561  }
562 
563 
564  //- Range of process indices for all processes
565  static rangeType allProcs(const label communicator = worldComm)
566  {
567  // Proc 0 -> nProcs (int value)
568  return rangeType(static_cast<int>(nProcs(communicator)));
569  }
570 
571  //- Range of process indices for sub-processes
572  static rangeType subProcs(const label communicator = worldComm)
573  {
574  // Proc 1 -> nProcs (int value)
575  return rangeType(1, static_cast<int>(nProcs(communicator)-1));
576  }
577 
578  //- Communication schedule for linear all-to-master (proc 0)
579  static const List<commsStruct>& linearCommunication
580  (
581  const label communicator = worldComm
582  )
583  {
584  return linearCommunication_[communicator];
585  }
586 
587  //- Communication schedule for tree all-to-master (proc 0)
588  static const List<commsStruct>& treeCommunication
589  (
590  const label communicator = worldComm
591  )
592  {
593  return treeCommunication_[communicator];
594  }
595 
596  //- Communication schedule for linear/tree all-to-master (proc 0).
597  //- Chooses based on the value of UPstream::nProcsSimpleSum
598  static const List<commsStruct>& whichCommunication
599  (
600  const label communicator = worldComm
601  )
602  {
603  return
604  (
605  nProcs(communicator) < nProcsSimpleSum
606  ? linearCommunication_[communicator]
607  : treeCommunication_[communicator]
608  );
609  }
610 
611 
612  //- Message tag of standard messages
613  static int& msgType() noexcept
614  {
615  return msgType_;
616  }
617 
618  //- Get the communications type of the stream
620  {
621  return commsType_;
622  }
623 
624  //- Set the communications type of the stream
625  // \return the previous value
627  {
628  commsTypes old(commsType_);
629  commsType_ = ct;
630  return old;
631  }
632 
633 
634  //- Shutdown (finalize) MPI as required.
635  // Uses MPI_Abort instead of MPI_Finalize if errNo is non-zero
636  static void shutdown(int errNo = 0);
637 
638  //- Call MPI_Abort with no other checks or cleanup
639  static void abort();
640 
641  //- Shutdown (finalize) MPI as required and exit program with errNo.
642  static void exit(int errNo = 1);
643 
644  //- Exchange integer data with all processors (in the communicator).
645  // \c sendData[proci] is the value to send to proci.
646  // After return recvData contains the data from the other processors.
647  static void allToAll
648  (
649  const UList<int32_t>& sendData,
650  UList<int32_t>& recvData,
651  const label communicator = worldComm
652  );
653 
654  //- Exchange integer data with all processors (in the communicator).
655  // \c sendData[proci] is the value to send to proci.
656  // After return recvData contains the data from the other processors.
657  static void allToAll
658  (
659  const UList<int64_t>& sendData,
660  UList<int64_t>& recvData,
661  const label communicator = worldComm
662  );
663 
665  // Low-level gather/scatter routines
666 
667  #undef Pstream_CommonRoutines
668  #define Pstream_CommonRoutines(Native) \
669  \
670  \
671  static void mpiGather \
672  ( \
673  const Native* sendData, \
674  int sendCount, \
675  char* recvData, \
676  int recvCount, \
677  const label communicator = worldComm \
678  ); \
679  \
680  \
681  static void mpiScatter \
682  ( \
683  const Native* sendData, \
684  int sendCount, \
685  char* recvData, \
686  int recvCount, \
687  const label communicator = worldComm \
688  ); \
689 
691 
692 
693  #undef Pstream_CommonRoutines
694  #define Pstream_CommonRoutines(Native) \
695  \
696  \
697  static void gather \
698  ( \
699  const Native* sendData, \
700  int sendCount, \
701  Native* recvData, \
702  const UList<int>& recvCounts, \
703  const UList<int>& recvOffsets, \
704  const label communicator = worldComm \
705  ); \
706  \
707  \
708  static void scatter \
709  ( \
710  const Native* sendData, \
711  const UList<int>& sendCounts, \
712  const UList<int>& sendOffsets, \
713  Native* recvData, \
714  int recvCount, \
715  const label communicator = worldComm \
716  );
717 
719  Pstream_CommonRoutines(int32_t);
720  Pstream_CommonRoutines(int64_t);
721  Pstream_CommonRoutines(uint32_t);
722  Pstream_CommonRoutines(uint64_t);
724  Pstream_CommonRoutines(double);
725 
726  #undef Pstream_CommonRoutines
727 
728 
729  // Gather single, contiguous value(s)
730 
731  //- Gather individual values into list locations.
732  // On master list length == nProcs, otherwise zero length.
733  // If called in non-parallel mode,
734  // the returned list length is 1 with localValue.
735  template<class T>
737  (
738  const T& localValue,
739  const label communicator = worldComm
740  );
741 
742  //- Scatter individual values from list locations.
743  // On master input list length == nProcs, ignored on other procs.
744  // If called in non-parallel mode,
745  // returns the first list element (or zero).
746  template<class T>
747  static T listScatterValues
748  (
749  const UList<T>& allValues,
750  const label communicator = worldComm
751  );
752 
753 
754  // Broadcast Functions
755 
756  //- Broadcast buffer contents to all processes in communicator.
757  //- The sizes must match on all processes.
758  // \return True on success
759  static bool broadcast
760  (
761  char* buf,
762  const std::streamsize bufSize,
763  const label communicator = worldComm,
764  const int rootProcNo = masterNo()
765  );
766 
768  // Logical reductions
769 
770  //- Logical (and) reduction (cf. MPI AllReduce)
771  static void reduceAnd
772  (
773  bool& value,
774  const label communicator = worldComm
775  );
776 
777  //- Logical (or) reduction (cf. MPI AllReduce)
778  static void reduceOr
779  (
780  bool& value,
781  const label communicator = worldComm
782  );
783 
784 
785  // Housekeeping
786 
787  //- Process index of first sub-process
788  // \deprecated(2020-09) use subProcs() method instead
789  static constexpr int firstSlave() noexcept
790  {
791  return 1;
792  }
793 
794  //- Process index of last sub-process
795  // \deprecated(2020-09) use subProcs() method instead
796  static int lastSlave(const label communicator = worldComm)
797  {
798  return nProcs(communicator) - 1;
799  }
800 };
801 
802 
803 Ostream& operator<<(Ostream&, const UPstream::commsStruct&);
804 
805 // Template specialisation for access of commsStruct
806 template<>
808 UList<UPstream::commsStruct>::operator[](const label procID);
809 
810 template<>
812 UList<UPstream::commsStruct>::operator[](const label procID) const;
813 
815 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
816 
817 } // End namespace Foam
818 
819 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
820 
821 #ifdef NoRepository
822  #include "UPstreamTemplates.C"
823 #endif
825 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
826 
827 #endif
828 
829 // ************************************************************************* //
static bool floatTransfer
Should compact transfer be used in which floats replace doubles reducing the bandwidth requirement at...
Definition: UPstream.H:327
const labelList & below() const noexcept
The procIDs of all processors directly below.
Definition: UPstream.H:162
static const word & myWorld()
My world.
Definition: UPstream.H:739
commsStruct() noexcept
Default construct. Above == -1.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
combineReduce operator for lists. Used for counting.
Definition: UPstream.H:201
"blocking" : (MPI_Bsend, MPI_Recv)
static const Enum< commsTypes > commsTypeNames
Enumerated names for the communication types.
Definition: UPstream.H:76
static const labelList & worldIDs() noexcept
The indices into allWorlds for all processes.
Definition: UPstream.H:723
~communicator()
Free allocated communicator and group.
Definition: UPstream.H:487
label comm() const noexcept
The communicator label.
Definition: UPstream.H:497
commsTypes
Types of communications.
Definition: UPstream.H:66
static label nRequests() noexcept
Number of outstanding requests.
Definition: UPstream.C:83
An interval of (signed) integers defined by a start and a size.
Definition: IntRange.H:59
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
Definition: UPstream.H:748
IntRange< int > rangeType
Int ranges are used for MPI ranks (processes)
Definition: UPstream.H:61
static int maxCommsSize
Optional maximum message size (bytes)
Definition: UPstream.H:347
static constexpr int firstSlave() noexcept
Process index of first sub-process.
Definition: UPstream.H:1016
static int nProcsSimpleSum
Number of processors to change from linear to tree communication.
Definition: UPstream.H:332
communicator() noexcept
Default construct (a placeholder communicator)
Definition: UPstream.H:459
static List< T > listGatherValues(const T &localValue, const label communicator=worldComm)
Gather individual values into list locations.
static bool initNull()
Special purpose initialisation function.
Definition: UPstream.C:30
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:639
static bool finishedRequest(const label i)
Non-blocking comms: has request i finished?
Definition: UPstream.C:101
static label procNo(const label comm, const int baseProcID)
Return processor number in communicator (given physical processor number) (= reverse of baseProcNo) ...
Definition: UPstream.C:299
static void reduceOr(bool &value, const label communicator=worldComm)
Logical (or) reduction (cf. MPI AllReduce)
void clear()
Reset to default constructed state.
static const List< commsStruct > & whichCommunication(const label communicator=worldComm)
Communication schedule for linear/tree all-to-master (proc 0). Chooses based on the value of UPstream...
Definition: UPstream.H:790
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:806
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:688
static label worldComm
Default world communicator (all processors). May differ from globalComm if local worlds are in use...
Definition: UPstream.H:361
label above() const noexcept
The procID of the processor directly above.
Definition: UPstream.H:154
static label allocateCommunicator(const label parent, const labelUList &subRanks, const bool doPstream=true)
Allocate a new communicator with subRanks of parent communicator.
Definition: UPstream.C:139
static const List< commsStruct > & treeCommunication(const label communicator=worldComm)
Communication schedule for tree all-to-master (proc 0)
Definition: UPstream.H:778
static void shutdown(int errNo=0)
Shutdown (finalize) MPI as required.
Definition: UPstream.C:51
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
ClassName("UPstream")
Declare name of the class and its debug switch.
void reset()
Free allocated communicator and group.
Definition: UPstream.H:502
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
T & operator[](const label i)
Return element of UList.
Definition: UListI.H:292
static void freeCommunicators(const bool doPstream)
Free all communicators.
Definition: UPstream.C:274
static int allocateTag(const char *const msg=nullptr)
Definition: UPstream.C:817
static constexpr label globalComm
Communicator for all processors, irrespective of any local worlds.
Definition: UPstream.H:371
scalar y
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator) is 1 for serial run.
Definition: UPstream.H:656
static int nPollProcInterfaces
Number of polling cycles in processor updates.
Definition: UPstream.H:342
static label parent(const label communicator)
The parent communicator.
Definition: UPstream.H:696
static void exit(int errNo=1)
Shutdown (finalize) MPI as required and exit program with errNo.
Definition: UPstream.C:55
static void reduceAnd(bool &value, const label communicator=worldComm)
Logical (and) reduction (cf. MPI AllReduce)
"scheduled" : (MPI_Send, MPI_Recv)
static bool init(int &argc, char **&argv, const bool needsThread)
Initialisation function called from main.
Definition: UPstream.C:40
static constexpr int masterNo() noexcept
Process index of the master (always 0)
Definition: UPstream.H:664
static const List< commsStruct > & linearCommunication(const label communicator=worldComm)
Communication schedule for linear all-to-master (proc 0)
Definition: UPstream.H:767
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:366
Structure for communicating between processors.
Definition: UPstream.H:84
const labelList & allBelow() const noexcept
The procIDs of all processors below (so not just directly below)
Definition: UPstream.H:171
static bool isUserComm(label communicator) noexcept
True if communicator appears to be user-allocated.
Definition: UPstream.H:386
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:814
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
bool operator==(const commsStruct &) const
static void allToAll(const UList< int32_t > &sendData, UList< int32_t > &recvData, const label communicator=worldComm)
Exchange integer data with all processors (in the communicator).
static void resetRequests(const label n)
Truncate outstanding requests to given length.
Definition: UPstream.C:89
static bool is_subrank(const label communicator=worldComm)
Is this process a sub-rank on the communicator.
Definition: UPstream.H:680
bool operator!=(const commsStruct &) const
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
Definition: UPstream.C:93
bool good() const noexcept
True if communicator is non-negative (ie, was allocated)
Definition: UPstream.H:492
Wrapper class for allocating/freeing communicators.
Definition: UPstream.H:440
const labelList & allNotBelow() const noexcept
The procIDs of all processors that are above. The inverse set of allBelow without myProcNo...
Definition: UPstream.H:180
static void abort()
Call MPI_Abort with no other checks or cleanup.
Definition: UPstream.C:62
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:76
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:337
void operator()(T &x, const T &y) const
Definition: UPstream.H:204
static int lastSlave(const label communicator=worldComm)
Process index of last sub-process.
Definition: UPstream.H:1026
static List< int > & procID(const label communicator)
Process IDs within a given communicator.
Definition: UPstream.H:704
static label nComms() noexcept
Number of currently defined communicators.
Definition: UPstream.H:381
UPstream(const commsTypes commsType)
Construct for given communication type.
Definition: UPstream.H:397
const dimensionedScalar c
Speed of light in a vacuum.
static bool master(const label communicator=worldComm)
Am I the master rank.
Definition: UPstream.H:672
"nonBlocking" : (MPI_Isend, MPI_Irecv)
label n
void operator=(const communicator &)=delete
No copy assignment.
static void freeTag(const int tag, const char *const msg=nullptr)
Definition: UPstream.C:841
static bool haveThreads() noexcept
Have support for threads.
Definition: UPstream.H:647
static bool broadcast(char *buf, const std::streamsize bufSize, const label communicator=worldComm, const int rootProcNo=masterNo())
Broadcast buffer contents to all processes in communicator. The sizes must match on all processes...
friend Ostream & operator<<(Ostream &, const commsStruct &)
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
Definition: UPstream.H:757
List< label > labelList
A List of labels.
Definition: List.H:62
static const int mpiBufferSize
MPI buffer-size (bytes)
Definition: UPstream.H:352
static const wordList & allWorlds() noexcept
All worlds.
Definition: UPstream.H:715
static T listScatterValues(const UList< T > &allValues, const label communicator=worldComm)
Scatter individual values from list locations.
#define Pstream_CommonRoutines(Native)
Definition: UPstream.H:905
static void waitRequest(const label i)
Wait until request i has finished.
Definition: UPstream.C:97
Inter-processor communications stream.
Definition: UPstream.H:54
static constexpr label selfComm
A communicator within the current rank only.
Definition: UPstream.H:376
static int baseProcNo(label comm, int procID)
Return physical processor number (i.e. processor number in worldComm) given communicator and processo...
Definition: UPstream.C:286
static void addValidParOptions(HashTable< string > &validParOptions)
Add the valid option this type of communications library adds/requires on the command line...
Definition: UPstream.C:26
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Definition: UPstream.C:239
Namespace for OpenFOAM.
static label myWorldID()
My worldID.
Definition: UPstream.H:731