PstreamBuffers.C
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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "PstreamBuffers.H"
29 
30 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
31 
33 
34 
35 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
36 
38 (
39  const UPstream::commsTypes commsType,
40  const int tag,
41  const label comm,
44 )
45 :
46  commsType_(commsType),
47  tag_(tag),
48  comm_(comm),
49  format_(format),
50  version_(version),
51  sendBuf_(UPstream::nProcs(comm)),
52  recvBuf_(UPstream::nProcs(comm)),
53  recvBufPos_(UPstream::nProcs(comm), 0),
54  finishedSendsCalled_(false)
55 {}
56 
57 
58 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
59 
61 {
62  // Check that all data has been consumed.
63  forAll(recvBufPos_, proci)
64  {
65  if (recvBufPos_[proci] < recvBuf_[proci].size())
66  {
68  << "Message from processor " << proci
69  << " not fully consumed. messageSize:" << recvBuf_[proci].size()
70  << " bytes of which only " << recvBufPos_[proci]
71  << " consumed."
73  }
74  }
75 }
76 
77 
78 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
79 
81 {
82  finishedSendsCalled_ = true;
83 
84  if (commsType_ == UPstream::commsTypes::nonBlocking)
85  {
86  Pstream::exchange<DynamicList<char>, char>
87  (
88  sendBuf_,
89  recvBuf_,
90  tag_,
91  comm_,
92  block
93  );
94  }
95 }
96 
97 
99 {
100  finishedSendsCalled_ = true;
101 
102  if (commsType_ == UPstream::commsTypes::nonBlocking)
103  {
104  Pstream::exchangeSizes(sendBuf_, recvSizes, comm_);
105 
106  Pstream::exchange<DynamicList<char>, char>
107  (
108  sendBuf_,
109  recvSizes,
110  recvBuf_,
111  tag_,
112  comm_,
113  block
114  );
115  }
116  else
117  {
119  << "Obtaining sizes not supported in "
120  << UPstream::commsTypeNames[commsType_] << endl
121  << " since transfers already in progress. Use non-blocking instead."
122  << exit(FatalError);
123 
124  // Note: maybe possible only if using different tag from write started
125  // by ~UOPstream. Needs some work.
126  }
127 }
128 
129 
131 {
132  for (DynamicList<char>& buf : sendBuf_)
133  {
134  buf.clear();
135  }
136  for (DynamicList<char>& buf : recvBuf_)
137  {
138  buf.clear();
139  }
140  recvBufPos_ = 0;
141  finishedSendsCalled_ = false;
142 }
143 
144 
145 // ************************************************************************* //
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:58
Foam::UPstream::commsTypes::nonBlocking
Foam::PstreamBuffers::~PstreamBuffers
~PstreamBuffers()
Destructor.
Definition: PstreamBuffers.C:60
Foam::DynamicList< char >
Foam::Pstream::exchangeSizes
static void exchangeSizes(const Container &sendData, labelList &sizes, const label comm=UPstream::worldComm)
Helper: exchange sizes of sendData. sendData is the data per.
Definition: exchange.C:349
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::PstreamBuffers::clear
void clear()
Clear storage and reset.
Definition: PstreamBuffers.C:130
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
format
word format(conversionProperties.get< word >("format"))
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::UPstream::commsTypeNames
static const Enum< commsTypes > commsTypeNames
Names of the communication types.
Definition: UPstream.H:77
Foam::PstreamBuffers::finishedSends
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
Definition: PstreamBuffers.C:80
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::foamVersion::version
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
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:38
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::List< label >
PstreamBuffers.H
Foam::PstreamBuffers::nullBuf
static DynamicList< char > nullBuf
Definition: PstreamBuffers.H:120