PstreamBuffers.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::PstreamBuffers
26 
27 Description
28  Buffers for inter-processor communications streams (UOPstream, UIPstream).
29 
30  Use UOPstream to stream data into buffers, call finishedSends() to
31  notify that data is in buffers and then use IUPstream to get data out
32  of received buffers. Works with both blocking and nonBlocking. Does
33  not make much sense with scheduled since there you would not need these
34  explicit buffers.
35 
36  Example usage:
37 
38  PstreamBuffers pBuffers(Pstream::commsTypes::nonBlocking);
39 
40  for (label proci = 0; proci < Pstream::nProcs(); proci++)
41  {
42  if (proci != Pstream::myProcNo())
43  {
44  someObject vals;
45 
46  UOPstream str(proci, pBuffers);
47  str << vals;
48  }
49  }
50 
51  pBuffers.finishedSends(); // no-op for blocking
52 
53  for (label proci = 0; proci < Pstream::nProcs(); proci++)
54  {
55  if (proci != Pstream::myProcNo())
56  {
57  UIPstream str(proci, pBuffers);
58  someObject vals(str);
59  }
60  }
61 
62 
63 SourceFiles
64  PstreamBuffers.C
65 
66 \*---------------------------------------------------------------------------*/
67 
68 #include "Pstream.H"
69 
70 #ifndef PstreamBuffers_H
71 #define PstreamBuffers_H
72 
73 #include "DynamicList.H"
74 #include "UPstream.H"
75 #include "IOstream.H"
76 
77 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
78 
79 namespace Foam
80 {
81 
82 /*---------------------------------------------------------------------------*\
83  Class PstreamBuffers Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class PstreamBuffers
87 {
88  friend class UOPstream;
89  friend class UIPstream;
90 
91  // Private Data
92 
93  //- Communications type of this stream
94  const UPstream::commsTypes commsType_;
95 
96  const int tag_;
97 
98  const label comm_;
99 
100  const IOstream::streamFormat format_;
101 
102  const IOstream::versionNumber version_;
103 
104  //- Send buffer
105  List<DynamicList<char>> sendBuf_;
106 
107  //- Receive buffer
108  List<DynamicList<char>> recvBuf_;
109 
110  //- Read position in recvBuf_
111  labelList recvBufPos_;
112 
113  bool finishedSendsCalled_;
114 
115 public:
116 
117  // Static data
119  static DynamicList<char> nullBuf;
120 
121 
122  // Constructors
123 
124  //- Construct given comms type,
125  // write format and IO version
127  (
128  const UPstream::commsTypes commsType,
129  const int tag = UPstream::msgType(),
130  const label comm = UPstream::worldComm,
133  );
134 
135  //- Destructor
136  ~PstreamBuffers();
137 
138 
139  // Member Functions
141  int tag() const
142  {
143  return tag_;
144  }
145 
146  //- Mark all sends as having been done. This will start receives
147  // in non-blocking mode. If block will wait for all transfers to
148  // finish (only relevant for nonBlocking mode)
149  void finishedSends(const bool block = true);
150 
151  //- Mark all sends as having been done. Same as above but also returns
152  // sizes (bytes) received. Note:currently only valid for
153  // non-blocking.
154  void finishedSends(labelList& recvSizes, const bool block = true);
155 
156  //- Clear storage and reset
157  void clear();
158 
159 };
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #endif
169 
170 // ************************************************************************* //
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
PstreamBuffers(const UPstream::commsTypes commsType, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, IOstream::streamFormat format=IOstream::BINARY, IOstream::versionNumber version=IOstream::currentVersion)
Construct given comms type,.
commsTypes
Types of communications.
Definition: UPstream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Holds information (coordinate and normal) regarding nearest wall point.
word format(conversionProperties.lookup("format"))
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:476
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:278
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:53
static DynamicList< char > nullBuf
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:63
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:54
~PstreamBuffers()
Destructor.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void clear()
Clear storage and reset.
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
Version number type.
Definition: IOstream.H:96
Namespace for OpenFOAM.