PstreamBuffers.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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::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
95 
96  const int tag_;
97 
98  const label comm_;
99 
101 
103 
104  //- Send buffer
106 
107  //- Receive buffer
109 
110  //- Read position in recvBuf_
112 
114 
115 public:
116 
117  // Static data
118 
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
140 
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) transferred. Note:currently only valid for
153  // non-blocking.
154  void finishedSends(labelListList& sizes, 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 // ************************************************************************* //
Foam::PstreamBuffers::format_
const IOstream::streamFormat format_
Definition: PstreamBuffers.H:99
Foam::PstreamBuffers::tag
int tag() const
Definition: PstreamBuffers.H:140
format
word format(conversionProperties.lookup("format"))
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:63
Foam::UOPstream
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:54
Foam::PstreamBuffers::~PstreamBuffers
~PstreamBuffers()
Destructor.
Definition: PstreamBuffers.C:62
UPstream.H
Foam::DynamicList< char >
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:85
Foam::PstreamBuffers::tag_
const int tag_
Definition: PstreamBuffers.H:95
Foam::PstreamBuffers::clear
void clear()
Clear storage and reset.
Definition: PstreamBuffers.C:146
Foam::IOstream::currentVersion
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
Foam::PstreamBuffers::version_
const IOstream::versionNumber version_
Definition: PstreamBuffers.H:101
Foam::IOstream::versionNumber
Version number type.
Definition: IOstream.H:96
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
IOstream.H
Foam::PstreamBuffers::finishedSends
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
Definition: PstreamBuffers.C:82
Foam::IOstream::BINARY
@ BINARY
Definition: IOstream.H:89
Pstream.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::PstreamBuffers::finishedSendsCalled_
bool finishedSendsCalled_
Definition: PstreamBuffers.H:112
Foam::PstreamBuffers::PstreamBuffers
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,.
Definition: PstreamBuffers.C:40
Foam::PstreamBuffers::commsType_
const UPstream::commsTypes commsType_
Communications type of this stream.
Definition: PstreamBuffers.H:93
Foam::PstreamBuffers::recvBuf_
List< DynamicList< char > > recvBuf_
Receive buffer.
Definition: PstreamBuffers.H:107
Foam::UPstream::msgType
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:452
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:64
Foam::UPstream::worldComm
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:258
Foam::List
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
Foam::PstreamBuffers::sendBuf_
List< DynamicList< char > > sendBuf_
Send buffer.
Definition: PstreamBuffers.H:104
Foam::PstreamBuffers::comm_
const label comm_
Definition: PstreamBuffers.H:97
DynamicList.H
Foam::UIPstream
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:53
Foam::PstreamBuffers::recvBufPos_
labelList recvBufPos_
Read position in recvBuf_.
Definition: PstreamBuffers.H:110
Foam::PstreamBuffers::nullBuf
static DynamicList< char > nullBuf
Definition: PstreamBuffers.H:118
Foam::IOstream::streamFormat
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86