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 mpiOPstreamImpl
28 \*---------------------------------------------------------------------------*/
32 #include "mpiOPstreamImpl.H"
33 #include <OpenFOAM/DynamicList.H>
34 #include <OpenFOAM/Pstream.H>
35 #include <OpenFOAM/addToRunTimeSelectionTable.H>
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 defineTypeNameAndDebug(mpiOPstreamImpl, 0);
43 addToRunTimeSelectionTable(OPstreamImpl, mpiOPstreamImpl, dictionary);
47 // Outstanding non-blocking operations.
49 Foam::DynamicList<MPI_Request> OPstream_outstandingRequests_;
50 //! @endcond fileScope
52 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
54 void Foam::mpiOPstreamImpl::flush
56 const PstreamImpl::commsTypes commsType,
73 FatalErrorIn("mpiOPstreamImpl::flush(const PstreamImpl::commsTypes, "
74 "const int, const char*, const int)")
75 << "MPI_Bsend cannot send outgoing message"
76 << Foam::abort(FatalError);
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 bool Foam::mpiOPstreamImpl::write
84 const PstreamImpl::commsTypes commsType,
87 const std::streamsize bufSize
90 bool transferFailed = true;
92 if (commsType == PstreamImpl::blocking)
94 transferFailed = MPI_Bsend
96 const_cast<char*>(buf),
99 Pstream::procID(toProcNo),
104 else if (commsType == PstreamImpl::scheduled)
106 transferFailed = MPI_Send
108 const_cast<char*>(buf),
111 Pstream::procID(toProcNo),
116 else if (commsType == PstreamImpl::nonBlocking)
120 transferFailed = MPI_Isend
122 const_cast<char*>(buf),
125 Pstream::procID(toProcNo),
131 OPstream_outstandingRequests_.append(request);
137 "mpiOPstreamImpl::write"
138 "(const int fromProcNo, char* buf, std::streamsize bufSize)"
139 ) << "Unsupported communications type " << commsType
140 << Foam::abort(FatalError);
143 return !transferFailed;
147 void Foam::mpiOPstreamImpl::waitRequests()
149 if (OPstream_outstandingRequests_.size())
155 OPstream_outstandingRequests_.size(),
156 OPstream_outstandingRequests_.begin(),
163 "mpiOPstreamImpl::waitRequests()"
164 ) << "MPI_Waitall returned with error" << Foam::endl;
167 OPstream_outstandingRequests_.clear();
172 bool Foam::mpiOPstreamImpl::finishedRequest(const label i)
174 if (i >= OPstream_outstandingRequests_.size())
178 "mpiOPstreamImpl::finishedRequest(const label)"
179 ) << "There are " << OPstream_outstandingRequests_.size()
180 << " outstanding send requests and you are asking for i=" << i
182 << "Maybe you are mixing blocking/non-blocking comms?"
183 << Foam::abort(FatalError);
187 MPI_Test(&OPstream_outstandingRequests_[i], &flag, MPI_STATUS_IGNORE);
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 // ************************ vim: set sw=4 sts=4 et: ************************ //