1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 Buffers for inter-processor communications streams (UOPstream, UIPstream).
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
38 PstreamBuffers pBuffers(Pstream::nonBlocking);
40 for (label procI = 0; procI < Pstream::nProcs(); procI++)
42 if (procI != Pstream::myProcNo())
46 UOPstream str(procI, pBuffers);
51 pBuffers.finishedSends(); // no-op for blocking
53 for (label procI = 0; procI < Pstream::nProcs(); procI++)
55 if (procI != Pstream::myProcNo())
57 UIPstream str(procI, pBuffers);
66 \*---------------------------------------------------------------------------*/
70 #ifndef PstreamBuffers_H
71 #define PstreamBuffers_H
73 #include "DynamicList.H"
77 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 /*---------------------------------------------------------------------------*\
83 Class PstreamBuffers Declaration
84 \*---------------------------------------------------------------------------*/
88 friend class UOPstream;
89 friend class UIPstream;
93 //- Communications type of this stream
94 const UPstream::commsTypes commsType_;
98 const IOstream::streamFormat format_;
100 const IOstream::versionNumber version_;
103 List<DynamicList<char> > sendBuf_;
106 List<DynamicList<char> > recvBuf_;
108 //- read position in recvBuf_
109 labelList recvBufPos_;
111 bool finishedSendsCalled_;
113 // Private Member Functions
119 static DynamicList<char> nullBuf;
124 //- Construct given comms type,
125 // write format and IO version
128 const UPstream::commsTypes commsType,
129 const int tag = UPstream::msgType(),
130 IOstream::streamFormat format=IOstream::BINARY,
131 IOstream::versionNumber version=IOstream::currentVersion
140 //- Mark all sends as having been done. This will start receives
141 // in non-blocking mode. If block will wait for all transfers to
142 // finish (only relevant for nonBlocking mode)
143 void finishedSends(const bool block = true);
145 //- Mark all sends as having been done. Same as above but also returns
146 // sizes (bytes) transferred. Note:currently only valid for
148 void finishedSends(labelListList& sizes, const bool block = true);
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 } // End namespace Foam
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 // ************************************************************************* //