OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

OPwrite.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Write primitive and binary block from OPstream gamma-mpi
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "OPstream.H"
00031 #include "long.H"
00032 #include "PstreamGlobals.H"
00033 
00034 extern "C" {
00035 
00036 #include <linux/gamma/libgamma.h>
00037 
00038 }
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 namespace Foam
00043 {
00044 
00045 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00046 
00047 // Largest message sent so far. This tracks the size of the receive
00048 // buffer on the receiving end. Done so we only send out resize messages
00049 // if necessary
00051 labelList maxSendSize;
00053 
00054 
00055 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00056 
00057 OPstream::~OPstream()
00058 {
00059     if (Pstream::debug)
00060     {
00061         Pout<< "OPstream::~OPstream() to processor " << toProcNo_
00062             << Foam::endl;
00063     }
00064 
00065     if
00066     (
00067        !write
00068         (
00069             commsType_,
00070             toProcNo_,
00071             buf_.begin(),
00072             bufPosition_
00073         )
00074     )
00075     {
00076         FatalErrorIn("OPstream::~OPstream()")
00077             << "GAMMA cannot send outgoing message"
00078             << Foam::abort(FatalError);
00079     }
00080 }
00081 
00082 
00083 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00084 
00085 bool OPstream::write
00086 (
00087     const commsTypes commsType,
00088     const int toProcNo,
00089     const char* buf,
00090     const std::streamsize bufSize
00091 )
00092 {
00093     if (PstreamGlobals::getSizeFromHeader(buf, bufSize) != -1)
00094     {
00095         FatalErrorIn("OPstream::write")
00096             << "Problem: Trying to send message of size " << bufSize
00097             << " that corresponds to the special resizeMessage."
00098             << Foam::abort(FatalError);
00099     }
00100 
00101     if (maxSendSize.empty())
00102     {
00103         // Intialize maxSendSize to the initial size of the receive buffers.
00104         maxSendSize.setSize(Pstream::nProcs());
00105         maxSendSize = PstreamGlobals::initialBufferLen;
00106         maxSendSize[Pstream::myProcNo()] = 0;
00107 
00108         if (Pstream::debug)
00109         {
00110             forAll(maxSendSize, procNo)
00111             {
00112                 Pout<< "OPstream::write() : for toProcNo:" << procNo
00113                     << " set maxSendSize to " << maxSendSize[procNo]
00114                     << Foam::endl;
00115             }
00116         }
00117     }
00118 
00119     if (Pstream::debug)
00120     {
00121         Pout<< "OPstream::write() : proc:" << toProcNo
00122             << " maxSendSize:" << maxSendSize[toProcNo]
00123             << Foam::endl;
00124     }
00125 
00126     if (bufSize > maxSendSize[toProcNo])
00127     {
00128         // Send resize message.
00129         if (Pstream::debug)
00130         {
00131             Pout<< "OPstream::write() : Sending resize message to proc "
00132             << toProcNo
00133             << " for size:" << bufSize
00134             << Foam::endl;
00135         }
00136 
00137         PstreamGlobals::setResizeMessage(bufSize);
00138         gamma_send_flowctl
00139         (
00140             toProcNo,
00141             reinterpret_cast<char*>(PstreamGlobals::resizeMessage),
00142             PstreamGlobals::resizeMessageLen*sizeof(uint64_t)
00143         );
00144 
00145         maxSendSize[toProcNo] = bufSize;
00146     }
00147 
00148 
00149     // Do normal send
00150     // ~~~~~~~~~~~~~~
00151 
00152     // Note: could be put into allocation of buf.
00153     //gamma_mlock(const_cast<char*>(buf), bufSize);
00154 
00155     if (Pstream::debug)
00156     {
00157         Pout<< "OPstream::write() : Sending to proc " << toProcNo
00158             << " bytes:" << bufSize << Foam::endl;
00159     }
00160 
00161     gamma_send_flowctl
00162     (
00163         toProcNo,
00164         const_cast<char*>(buf),
00165         bufSize
00166     );
00167 
00168     //gamma_munlock(const_cast<char*>(buf), bufSize);
00169 
00170     if (Pstream::debug)
00171     {
00172         Pout<< "OPstream::write() : Sent " << bufSize
00173             << " to proc " << toProcNo
00174             << Foam::endl;
00175     }
00176 
00177 
00178     return true;
00179 }
00180 
00181 
00182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00183 
00184 } // End namespace Foam
00185 
00186 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd