initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / Pstream / gamma / OPwrite.C
blob00eaa13f817efd505686b6a71f6e429440e6fcf5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Description
26     Write primitive and binary block from OPstream gamma-mpi
28 \*---------------------------------------------------------------------------*/
30 #include "OPstream.H"
31 #include "long.H"
32 #include "PstreamGlobals.H"
34 extern "C" {
36 #include <linux/gamma/libgamma.h>
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 namespace Foam
45 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
47 // Largest message sent so far. This tracks the size of the receive
48 // buffer on the receiving end. Done so we only send out resize messages
49 // if necessary
50 //! @cond fileScope
51 labelList maxSendSize;
52 //! @endcond fileScope
55 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
57 OPstream::~OPstream()
59     if (Pstream::debug)
60     {
61         Pout<< "OPstream::~OPstream() to processor " << toProcNo_
62             << Foam::endl;
63     }
65     if
66     (
67        !write
68         (
69             commsType_,
70             toProcNo_,
71             buf_.begin(),
72             bufPosition_
73         )
74     )
75     {
76         FatalErrorIn("OPstream::~OPstream()")
77             << "GAMMA cannot send outgoing message"
78             << Foam::abort(FatalError);
79     }
83 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
85 bool OPstream::write
87     const commsTypes commsType,
88     const int toProcNo,
89     const char* buf,
90     const std::streamsize bufSize
93     if (PstreamGlobals::getSizeFromHeader(buf, bufSize) != -1)
94     {
95         FatalErrorIn("OPstream::write")
96             << "Problem: Trying to send message of size " << bufSize
97             << " that corresponds to the special resizeMessage."
98             << Foam::abort(FatalError);
99     }
101     if (maxSendSize.empty())
102     {
103         // Intialize maxSendSize to the initial size of the receive buffers.
104         maxSendSize.setSize(Pstream::nProcs());
105         maxSendSize = PstreamGlobals::initialBufferLen;
106         maxSendSize[Pstream::myProcNo()] = 0;
108         if (Pstream::debug)
109         {
110             forAll(maxSendSize, procNo)
111             {
112                 Pout<< "OPstream::write() : for toProcNo:" << procNo
113                     << " set maxSendSize to " << maxSendSize[procNo]
114                     << Foam::endl;
115             }
116         }
117     }
119     if (Pstream::debug)
120     {
121         Pout<< "OPstream::write() : proc:" << toProcNo
122             << " maxSendSize:" << maxSendSize[toProcNo]
123             << Foam::endl;
124     }
126     if (bufSize > maxSendSize[toProcNo])
127     {
128         // Send resize message.
129         if (Pstream::debug)
130         {
131             Pout<< "OPstream::write() : Sending resize message to proc "
132             << toProcNo
133             << " for size:" << bufSize
134             << Foam::endl;
135         }
137         PstreamGlobals::setResizeMessage(bufSize);
138         gamma_send_flowctl
139         (
140             toProcNo,
141             reinterpret_cast<char*>(PstreamGlobals::resizeMessage),
142             PstreamGlobals::resizeMessageLen*sizeof(uint64_t)
143         );
145         maxSendSize[toProcNo] = bufSize;
146     }
149     // Do normal send
150     // ~~~~~~~~~~~~~~
152     // Note: could be put into allocation of buf.
153     //gamma_mlock(const_cast<char*>(buf), bufSize);
155     if (Pstream::debug)
156     {
157         Pout<< "OPstream::write() : Sending to proc " << toProcNo
158             << " bytes:" << bufSize << Foam::endl;
159     }
161     gamma_send_flowctl
162     (
163         toProcNo,
164         const_cast<char*>(buf),
165         bufSize
166     );
168     //gamma_munlock(const_cast<char*>(buf), bufSize);
170     if (Pstream::debug)
171     {
172         Pout<< "OPstream::write() : Sent " << bufSize
173             << " to proc " << toProcNo
174             << Foam::endl;
175     }
178     return true;
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 } // End namespace Foam
186 // ************************************************************************* //