1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
25 \*---------------------------------------------------------------------------*/
27 #include "processorLduInterface.H"
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 void Foam::processorLduInterface::send
36 const Pstream::commsTypes commsType,
40 if (commsType == Pstream::blocking || commsType == Pstream::scheduled)
46 reinterpret_cast<const char*>(f.begin()),
50 else if (commsType == Pstream::nonBlocking)
52 resizeBuf(receiveBuf_, f.size()*sizeof(Type));
62 resizeBuf(sendBuf_, f.byteSize());
63 memcpy(sendBuf_.begin(), f.begin(), f.byteSize());
75 FatalErrorIn("processorLduInterface::send")
76 << "Unsupported communications type " << commsType
83 void Foam::processorLduInterface::receive
85 const Pstream::commsTypes commsType,
89 if (commsType == Pstream::blocking || commsType == Pstream::scheduled)
95 reinterpret_cast<char*>(f.begin()),
99 else if (commsType == Pstream::nonBlocking)
101 memcpy(f.begin(), receiveBuf_.begin(), f.byteSize());
105 FatalErrorIn("processorLduInterface::receive")
106 << "Unsupported communications type " << commsType
113 Foam::tmp<Foam::Field<Type> > Foam::processorLduInterface::receive
115 const Pstream::commsTypes commsType,
119 tmp<Field<Type> > tf(new Field<Type>(size));
120 receive(commsType, tf());
126 void Foam::processorLduInterface::compressedSend
128 const Pstream::commsTypes commsType,
132 if (sizeof(scalar) != sizeof(float) && Pstream::floatTransfer && f.size())
134 static const label nCmpts = sizeof(Type)/sizeof(scalar);
135 label nm1 = (f.size() - 1)*nCmpts;
136 label nlast = sizeof(Type)/sizeof(float);
137 label nFloats = nm1 + nlast;
138 label nBytes = nFloats*sizeof(float);
140 const scalar *sArray = reinterpret_cast<const scalar*>(f.begin());
141 const scalar *slast = &sArray[nm1];
142 resizeBuf(sendBuf_, nBytes);
143 float *fArray = reinterpret_cast<float*>(sendBuf_.begin());
145 for (register label i=0; i<nm1; i++)
147 fArray[i] = sArray[i] - slast[i%nCmpts];
150 reinterpret_cast<Type&>(fArray[nm1]) = f[f.size() - 1];
152 if (commsType == Pstream::blocking || commsType == Pstream::scheduled)
162 else if (commsType == Pstream::nonBlocking)
164 resizeBuf(receiveBuf_, nBytes);
184 FatalErrorIn("processorLduInterface::compressedSend")
185 << "Unsupported communications type " << commsType
191 this->send(commsType, f);
196 void Foam::processorLduInterface::compressedReceive
198 const Pstream::commsTypes commsType,
202 if (sizeof(scalar) != sizeof(float) && Pstream::floatTransfer && f.size())
204 static const label nCmpts = sizeof(Type)/sizeof(scalar);
205 label nm1 = (f.size() - 1)*nCmpts;
206 label nlast = sizeof(Type)/sizeof(float);
207 label nFloats = nm1 + nlast;
208 label nBytes = nFloats*sizeof(float);
210 if (commsType == Pstream::blocking || commsType == Pstream::scheduled)
212 resizeBuf(receiveBuf_, nBytes);
222 else if (commsType != Pstream::nonBlocking)
224 FatalErrorIn("processorLduInterface::compressedReceive")
225 << "Unsupported communications type " << commsType
229 const float *fArray =
230 reinterpret_cast<const float*>(receiveBuf_.begin());
231 f[f.size() - 1] = reinterpret_cast<const Type&>(fArray[nm1]);
232 scalar *sArray = reinterpret_cast<scalar*>(f.begin());
233 const scalar *slast = &sArray[nm1];
235 for (register label i=0; i<nm1; i++)
237 sArray[i] = fArray[i] + slast[i%nCmpts];
242 this->receive<Type>(commsType, f);
247 Foam::tmp<Foam::Field<Type> > Foam::processorLduInterface::compressedReceive
249 const Pstream::commsTypes commsType,
253 tmp<Field<Type> > tf(new Field<Type>(size));
254 compressedReceive(commsType, tf());
259 // ************************************************************************* //