1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 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/>.
25 Write primitive and binary block from OPstream gamma-mpi
27 \*---------------------------------------------------------------------------*/
31 #include "PstreamGlobals.H"
35 #include <linux/gamma/libgamma.h>
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
46 // Largest message sent so far. This tracks the size of the receive
47 // buffer on the receiving end. Done so we only send out resize messages
50 labelList maxSendSize;
54 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
60 Pout<< "OPstream::~OPstream() to processor " << toProcNo_
75 FatalErrorIn("OPstream::~OPstream()")
76 << "GAMMA cannot send outgoing message"
77 << Foam::abort(FatalError);
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 const commsTypes commsType,
89 const std::streamsize bufSize
92 if (PstreamGlobals::getSizeFromHeader(buf, bufSize) != -1)
94 FatalErrorIn("OPstream::write")
95 << "Problem: Trying to send message of size " << bufSize
96 << " that corresponds to the special resizeMessage."
97 << Foam::abort(FatalError);
100 if (maxSendSize.empty())
102 // Intialize maxSendSize to the initial size of the receive buffers.
103 maxSendSize.setSize(Pstream::nProcs());
104 maxSendSize = PstreamGlobals::initialBufferLen;
105 maxSendSize[Pstream::myProcNo()] = 0;
109 forAll(maxSendSize, procNo)
111 Pout<< "OPstream::write() : for toProcNo:" << procNo
112 << " set maxSendSize to " << maxSendSize[procNo]
120 Pout<< "OPstream::write() : proc:" << toProcNo
121 << " maxSendSize:" << maxSendSize[toProcNo]
125 if (bufSize > maxSendSize[toProcNo])
127 // Send resize message.
130 Pout<< "OPstream::write() : Sending resize message to proc "
132 << " for size:" << bufSize
136 PstreamGlobals::setResizeMessage(bufSize);
140 reinterpret_cast<char*>(PstreamGlobals::resizeMessage),
141 PstreamGlobals::resizeMessageLen*sizeof(uint64_t)
144 maxSendSize[toProcNo] = bufSize;
151 // Note: could be put into allocation of buf.
152 //gamma_mlock(const_cast<char*>(buf), bufSize);
156 Pout<< "OPstream::write() : Sending to proc " << toProcNo
157 << " bytes:" << bufSize << Foam::endl;
163 const_cast<char*>(buf),
167 //gamma_munlock(const_cast<char*>(buf), bufSize);
171 Pout<< "OPstream::write() : Sent " << bufSize
172 << " to proc " << toProcNo
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 } // End namespace Foam
185 // ************************************************************************* //