1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Write primitive and binary block from OPstream
28 \*---------------------------------------------------------------------------*/
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 // Outstanding non-blocking operations.
38 Foam::DynamicList<MPI_Request> OPstream_outstandingRequests_;
39 //! @endcond fileScope
41 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
43 Foam::OPstream::~OPstream()
56 FatalErrorIn("OPstream::~OPstream()")
57 << "MPI_Bsend cannot send outgoing message"
58 << Foam::abort(FatalError);
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 bool Foam::OPstream::write
67 const commsTypes commsType,
70 const std::streamsize bufSize
73 bool transferFailed = true;
75 if (commsType == blocking)
77 transferFailed = MPI_Bsend
79 const_cast<char*>(buf),
87 else if (commsType == scheduled)
89 transferFailed = MPI_Send
91 const_cast<char*>(buf),
99 else if (commsType == nonBlocking)
103 transferFailed = MPI_Isend
105 const_cast<char*>(buf),
114 OPstream_outstandingRequests_.append(request);
121 "(const int fromProcNo, char* buf, std::streamsize bufSize)"
122 ) << "Unsupported communications type " << commsType
123 << Foam::abort(FatalError);
126 return !transferFailed;
130 void Foam::OPstream::waitRequests()
132 if (OPstream_outstandingRequests_.size())
138 OPstream_outstandingRequests_.size(),
139 OPstream_outstandingRequests_.begin(),
146 "OPstream::waitRequests()"
147 ) << "MPI_Waitall returned with error" << Foam::endl;
150 OPstream_outstandingRequests_.clear();
155 bool Foam::OPstream::finishedRequest(const label i)
157 if (i >= OPstream_outstandingRequests_.size())
161 "OPstream::finishedRequest(const label)"
162 ) << "There are " << OPstream_outstandingRequests_.size()
163 << " outstanding send requests and you are asking for i=" << i
165 << "Maybe you are mixing blocking/non-blocking comms?"
166 << Foam::abort(FatalError);
170 MPI_Test(&OPstream_outstandingRequests_[i], &flag, MPI_STATUS_IGNORE);
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 // ************************************************************************* //