1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "PstreamBuffers.H"
28 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
33 DynamicList<char> PstreamBuffers::nullBuf(0);
37 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
39 Foam::PstreamBuffers::PstreamBuffers
41 const UPstream::commsTypes commsType,
43 IOstream::streamFormat format,
44 IOstream::versionNumber version
47 commsType_(commsType),
51 sendBuf_(UPstream::nProcs()),
52 recvBuf_(UPstream::nProcs()),
53 recvBufPos_(UPstream::nProcs(), 0),
54 finishedSendsCalled_(false)
58 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
60 Foam::PstreamBuffers::~PstreamBuffers()
62 // Check that all data has been consumed.
63 forAll(recvBufPos_, procI)
65 if (recvBufPos_[procI] < recvBuf_[procI].size())
67 FatalErrorIn("PstreamBuffers::~PstreamBuffers()")
68 << "Message from processor " << procI
69 << " not fully consumed. messageSize:" << recvBuf_[procI].size()
70 << " bytes of which only " << recvBufPos_[procI]
72 << Foam::abort(FatalError);
78 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
80 void Foam::PstreamBuffers::finishedSends(const bool block)
82 finishedSendsCalled_ = true;
84 if (commsType_ == UPstream::nonBlocking)
87 Pstream::exchange<DynamicList<char>, char>
99 void Foam::PstreamBuffers::finishedSends(labelListList& sizes, const bool block)
101 finishedSendsCalled_ = true;
103 if (commsType_ == UPstream::nonBlocking)
105 Pstream::exchange<DynamicList<char>, char>
118 "PstreamBuffers::finishedSends(labelListList&, const bool)"
119 ) << "Obtaining sizes not supported in "
120 << UPstream::commsTypeNames[commsType_] << endl
121 << " since transfers already in progress. Use non-blocking instead."
124 // Note: possible only if using different tag from write started
125 // by ~UOPstream. Needs some work.
126 //sizes.setSize(UPstream::nProcs());
127 //labelList& nsTransPs = sizes[UPstream::myProcNo()];
128 //nsTransPs.setSize(UPstream::nProcs());
130 //forAll(sendBuf_, procI)
132 // nsTransPs[procI] = sendBuf_[procI].size();
135 //// Send sizes across.
136 //int oldTag = UPstream::msgType();
137 //UPstream::msgType() = tag_;
138 //combineReduce(sizes, UPstream::listEq());
139 //UPstream::msgType() = oldTag;
144 // ************************************************************************* //