mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'master' of ssh://noisy/home/noisy3/OpenFOAM/OpenFOAM-dev
This commit is contained in:
@ -22,27 +22,45 @@ License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
Prints out a description of the streams
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
#include "argList.H"
|
||||
|
||||
#include "IPstream.H"
|
||||
#include "OPstream.H"
|
||||
#include "vector.H"
|
||||
#include "IFstream.H"
|
||||
#include "BSpline.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
void Foam::IPstream::print(Ostream& os) const
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
os << "Reading from processor " << fromProcNo_
|
||||
<< " to processor " << myProcNo() << Foam::endl;
|
||||
}
|
||||
argList::noParallel();
|
||||
argList::validArgs.insert("file .. fileN");
|
||||
|
||||
argList args(argc, argv, false, true);
|
||||
|
||||
forAll(args.additionalArgs(), argI)
|
||||
{
|
||||
const string& srcFile = args.additionalArgs()[argI];
|
||||
Info<< nl << "reading " << srcFile << nl;
|
||||
IFstream ifs(srcFile);
|
||||
|
||||
List<pointField> splinePointFields(ifs);
|
||||
|
||||
forAll(splinePointFields, splineI)
|
||||
{
|
||||
Info<<"convert " << splinePointFields[splineI] << " to bspline" << endl;
|
||||
|
||||
BSpline spl(splinePointFields[splineI], vector::zero, vector::zero);
|
||||
|
||||
Info<< "1/2 = " << spl.position(0.5) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::OPstream::print(Ostream& os) const
|
||||
{
|
||||
os << "Writing from processor " << toProcNo_
|
||||
<< " to processor " << myProcNo() << Foam::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
3
applications/test/BSpline/Make/files
Normal file
3
applications/test/BSpline/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
BSplineTest.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/BSplineTest
|
||||
5
applications/test/BSpline/Make/options
Normal file
5
applications/test/BSpline/Make/options
Normal file
@ -0,0 +1,5 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude \
|
||||
-I$(LIB_SRC)/mesh/blockMesh/lnInclude
|
||||
|
||||
EXE_LIBS = -lblockMesh
|
||||
69
applications/test/BSpline/test-splines
Normal file
69
applications/test/BSpline/test-splines
Normal file
@ -0,0 +1,69 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: http://www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
(
|
||||
// Upper body longitudinal splines.
|
||||
(
|
||||
(-0.22685 -0.01125166 0) // 7
|
||||
(-0.21685 -0.01340204 0)
|
||||
(-0.20685 -0.01529684 0)
|
||||
(-0.19685 -0.01694748 0)
|
||||
(-0.18685 -0.01836538 0)
|
||||
(-0.17685 -0.01956197 0)
|
||||
(-0.16685 -0.02054868 0)
|
||||
(-0.15685 -0.02133693 0)
|
||||
(-0.14685 -0.02193816 0)
|
||||
(-0.13685 -0.02236377 0)
|
||||
(-0.12685 -0.02262521 0)
|
||||
(-0.11685 -0.02273389 0) // 2
|
||||
)
|
||||
|
||||
(
|
||||
(-0.22685 0 0.01125166) // 8
|
||||
(-0.21685 0 0.01340204)
|
||||
(-0.20685 0 0.01529684)
|
||||
(-0.19685 0 0.01694748)
|
||||
(-0.18685 0 0.01836538)
|
||||
(-0.17685 0 0.01956197)
|
||||
(-0.16685 0 0.02054868)
|
||||
(-0.15685 0 0.02133693)
|
||||
(-0.14685 0 0.02193816)
|
||||
(-0.13685 0 0.02236377)
|
||||
(-0.12685 0 0.02262521)
|
||||
(-0.11685 0 0.02273389) // 3
|
||||
)
|
||||
|
||||
(
|
||||
(-0.22685 0.01125166 0) // 9
|
||||
(-0.21685 0.01340204 0)
|
||||
(-0.20685 0.01529684 0)
|
||||
(-0.19685 0.01694748 0)
|
||||
(-0.18685 0.01836538 0)
|
||||
(-0.17685 0.01956197 0)
|
||||
(-0.16685 0.02054868 0)
|
||||
(-0.15685 0.02133693 0)
|
||||
(-0.14685 0.02193816 0)
|
||||
(-0.13685 0.02236377 0)
|
||||
(-0.12685 0.02262521 0)
|
||||
(-0.11685 0.02273389 0) // 4
|
||||
)
|
||||
|
||||
(
|
||||
(-0.22685 0 -0.01125166) // 6
|
||||
(-0.21685 0 -0.01340204)
|
||||
(-0.20685 0 -0.01529684)
|
||||
(-0.19685 0 -0.01694748)
|
||||
(-0.18685 0 -0.01836538)
|
||||
(-0.17685 0 -0.01956197)
|
||||
(-0.16685 0 -0.02054868)
|
||||
(-0.15685 0 -0.02133693)
|
||||
(-0.14685 0 -0.02193816)
|
||||
(-0.13685 0 -0.02236377)
|
||||
(-0.12685 0 -0.02262521)
|
||||
(-0.11685 0 -0.02273389) // 1
|
||||
)
|
||||
);
|
||||
@ -22,13 +22,9 @@ License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "GatherBase.H"
|
||||
#include "IPstream.H"
|
||||
#include "OPstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -108,11 +108,14 @@ StringStreams = $(Streams)/StringStreams
|
||||
$(StringStreams)/StringStreamsPrint.C
|
||||
|
||||
Pstreams = $(Streams)/Pstreams
|
||||
$(Pstreams)/Pstream.C
|
||||
$(Pstreams)/PstreamCommsStruct.C
|
||||
$(Pstreams)/UIPstream.C
|
||||
$(Pstreams)/IPstream.C
|
||||
$(Pstreams)/UPstream.C
|
||||
$(Pstreams)/UPstreamCommsStruct.C
|
||||
$(Pstreams)/Pstream.C
|
||||
$(Pstreams)/UOPstream.C
|
||||
$(Pstreams)/OPstream.C
|
||||
$(Pstreams)/PstreamsPrint.C
|
||||
$(Pstreams)/PstreamBuffers.C
|
||||
|
||||
dictionary = db/dictionary
|
||||
$(dictionary)/dictionary.C
|
||||
|
||||
@ -114,7 +114,7 @@ void Foam::ParSortableList<Type>::checkAndSend
|
||||
}
|
||||
|
||||
{
|
||||
OPstream toSlave(destProcI);
|
||||
OPstream toSlave(Pstream::blocking, destProcI);
|
||||
toSlave << values << indices;
|
||||
}
|
||||
}
|
||||
@ -311,7 +311,7 @@ void Foam::ParSortableList<Type>::sort()
|
||||
Pout<< "Receiving from " << procI << endl;
|
||||
}
|
||||
|
||||
IPstream fromSlave(procI);
|
||||
IPstream fromSlave(Pstream::blocking, procI);
|
||||
|
||||
fromSlave >> recValues >> recIndices;
|
||||
|
||||
|
||||
@ -24,291 +24,22 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "IPstream.H"
|
||||
#include "int.H"
|
||||
#include "token.H"
|
||||
#include <cctype>
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::IPstream::checkEof()
|
||||
{
|
||||
if (bufPosition_ == messageSize_)
|
||||
{
|
||||
setEof();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::IPstream::readFromBuffer(T& t)
|
||||
{
|
||||
const size_t align = sizeof(T);
|
||||
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
|
||||
|
||||
t = reinterpret_cast<T&>(buf_[bufPosition_]);
|
||||
bufPosition_ += sizeof(T);
|
||||
checkEof();
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::IPstream::readFromBuffer
|
||||
Foam::IPstream::IPstream
|
||||
(
|
||||
void* data,
|
||||
size_t count,
|
||||
size_t align
|
||||
const commsTypes commsType,
|
||||
const int fromProcNo,
|
||||
const label bufSize,
|
||||
streamFormat format,
|
||||
versionNumber version
|
||||
)
|
||||
{
|
||||
if (align > 1)
|
||||
{
|
||||
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
|
||||
}
|
||||
|
||||
register const char* bufPtr = &buf_[bufPosition_];
|
||||
register char* dataPtr = reinterpret_cast<char*>(data);
|
||||
register size_t i = count;
|
||||
while (i--) *dataPtr++ = *bufPtr++;
|
||||
bufPosition_ += count;
|
||||
checkEof();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IPstream::~IPstream()
|
||||
{
|
||||
if (bufPosition_ < messageSize_)
|
||||
{
|
||||
FatalErrorIn("IPstream::~IPstream()")
|
||||
<< "Message not fully consumed. messageSize:" << messageSize_
|
||||
<< " bytes of which only " << bufPosition_
|
||||
<< " consumed." << Foam::abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Istream& Foam::IPstream::read(token& t)
|
||||
{
|
||||
// Return the put back token if it exists
|
||||
if (Istream::getBack(t))
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
char c;
|
||||
|
||||
// return on error
|
||||
if (!read(c))
|
||||
{
|
||||
t.setBad();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Set the line number of this token to the current stream line number
|
||||
t.lineNumber() = lineNumber();
|
||||
|
||||
// Analyse input starting with this character.
|
||||
switch (c)
|
||||
{
|
||||
// Punctuation
|
||||
case token::END_STATEMENT :
|
||||
case token::BEGIN_LIST :
|
||||
case token::END_LIST :
|
||||
case token::BEGIN_SQR :
|
||||
case token::END_SQR :
|
||||
case token::BEGIN_BLOCK :
|
||||
case token::END_BLOCK :
|
||||
case token::COLON :
|
||||
case token::COMMA :
|
||||
case token::ASSIGN :
|
||||
case token::ADD :
|
||||
case token::SUBTRACT :
|
||||
case token::MULTIPLY :
|
||||
case token::DIVIDE :
|
||||
{
|
||||
t = token::punctuationToken(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Word
|
||||
case token::WORD :
|
||||
{
|
||||
word* pval = new word;
|
||||
if (read(*pval))
|
||||
{
|
||||
if (token::compound::isCompound(*pval))
|
||||
{
|
||||
t = token::compound::New(*pval, *this).ptr();
|
||||
delete pval;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = pval;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pval;
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// String
|
||||
case token::STRING :
|
||||
{
|
||||
string* pval = new string;
|
||||
if (read(*pval))
|
||||
{
|
||||
t = pval;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pval;
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Label
|
||||
case token::LABEL :
|
||||
{
|
||||
label val;
|
||||
if (read(val))
|
||||
{
|
||||
t = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// floatScalar
|
||||
case token::FLOAT_SCALAR :
|
||||
{
|
||||
floatScalar val;
|
||||
if (read(val))
|
||||
{
|
||||
t = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// doubleScalar
|
||||
case token::DOUBLE_SCALAR :
|
||||
{
|
||||
doubleScalar val;
|
||||
if (read(val))
|
||||
{
|
||||
t = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Character (returned as a single character word) or error
|
||||
default:
|
||||
{
|
||||
if (isalpha(c))
|
||||
{
|
||||
t = word(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
setBad();
|
||||
t.setBad();
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::IPstream::read(char& c)
|
||||
{
|
||||
c = buf_[bufPosition_];
|
||||
bufPosition_++;
|
||||
checkEof();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::IPstream::read(word& str)
|
||||
{
|
||||
size_t len;
|
||||
readFromBuffer(len);
|
||||
str = &buf_[bufPosition_];
|
||||
bufPosition_ += len + 1;
|
||||
checkEof();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::IPstream::read(string& str)
|
||||
{
|
||||
size_t len;
|
||||
readFromBuffer(len);
|
||||
str = &buf_[bufPosition_];
|
||||
bufPosition_ += len + 1;
|
||||
checkEof();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::IPstream::read(label& val)
|
||||
{
|
||||
readFromBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::IPstream::read(floatScalar& val)
|
||||
{
|
||||
readFromBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::IPstream::read(doubleScalar& val)
|
||||
{
|
||||
readFromBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::IPstream::read(char* data, std::streamsize count)
|
||||
{
|
||||
if (format() != BINARY)
|
||||
{
|
||||
FatalErrorIn("IPstream::read(char*, std::streamsize)")
|
||||
<< "stream format not binary"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
readFromBuffer(data, count, 8);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::IPstream::rewind()
|
||||
{
|
||||
bufPosition_ = 0;
|
||||
return *this;
|
||||
}
|
||||
:
|
||||
Pstream(commsType, bufSize),
|
||||
UIPstream(commsType, fromProcNo, buf_)
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -38,7 +38,7 @@ SourceFiles
|
||||
#ifndef IPstream_H
|
||||
#define IPstream_H
|
||||
|
||||
#include "Istream.H"
|
||||
#include "UIPstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -52,26 +52,8 @@ namespace Foam
|
||||
class IPstream
|
||||
:
|
||||
public Pstream,
|
||||
public Istream
|
||||
public UIPstream
|
||||
{
|
||||
// Private data
|
||||
|
||||
int fromProcNo_;
|
||||
label messageSize_;
|
||||
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Check the bufferPosition_ against messageSize_ for EOF
|
||||
inline void checkEof();
|
||||
|
||||
//- Read a T from the transfer buffer
|
||||
template<class T>
|
||||
inline void readFromBuffer(T&);
|
||||
|
||||
//- Read data from the transfer buffer
|
||||
inline void readFromBuffer(void* data, size_t count, size_t align);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -88,76 +70,6 @@ public:
|
||||
versionNumber version=currentVersion
|
||||
);
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
~IPstream();
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Inquiry
|
||||
|
||||
//- Return flags of output stream
|
||||
ios_base::fmtflags flags() const
|
||||
{
|
||||
return ios_base::fmtflags(0);
|
||||
}
|
||||
|
||||
|
||||
// Read functions
|
||||
|
||||
//- Read into given buffer from given processor and return the
|
||||
// message size
|
||||
static label read
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int fromProcNo,
|
||||
char* buf,
|
||||
const std::streamsize bufSize
|
||||
);
|
||||
|
||||
//- Return next token from stream
|
||||
Istream& read(token&);
|
||||
|
||||
//- Read a character
|
||||
Istream& read(char&);
|
||||
|
||||
//- Read a word
|
||||
Istream& read(word&);
|
||||
|
||||
// Read a string (including enclosing double-quotes)
|
||||
Istream& read(string&);
|
||||
|
||||
//- Read a label
|
||||
Istream& read(label&);
|
||||
|
||||
//- Read a floatScalar
|
||||
Istream& read(floatScalar&);
|
||||
|
||||
//- Read a doubleScalar
|
||||
Istream& read(doubleScalar&);
|
||||
|
||||
//- Read binary block
|
||||
Istream& read(char*, std::streamsize);
|
||||
|
||||
//- Rewind and return the stream so that it may be read again
|
||||
Istream& rewind();
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Set flags of stream
|
||||
ios_base::fmtflags flags(const ios_base::fmtflags)
|
||||
{
|
||||
return ios_base::fmtflags(0);
|
||||
}
|
||||
|
||||
|
||||
// Print
|
||||
|
||||
//- Print description of IOstream to Ostream
|
||||
void print(Ostream&) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -22,68 +22,9 @@ License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
Write primitive and binary block from OPstream
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
|
||||
#include "OPstream.H"
|
||||
#include "int.H"
|
||||
#include "token.H"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline void Foam::OPstream::writeToBuffer(const T& t)
|
||||
{
|
||||
writeToBuffer(&t, sizeof(T), sizeof(T));
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::OPstream::writeToBuffer(const char& c)
|
||||
{
|
||||
if (size_t(buf_.size()) < bufPosition_ + 1U)
|
||||
{
|
||||
enlargeBuffer(1);
|
||||
}
|
||||
|
||||
buf_[bufPosition_] = c;
|
||||
bufPosition_ ++;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::OPstream::writeToBuffer
|
||||
(
|
||||
const void* data,
|
||||
size_t count,
|
||||
size_t align
|
||||
)
|
||||
{
|
||||
label oldPos = bufPosition_;
|
||||
|
||||
if (align > 1)
|
||||
{
|
||||
// Align bufPosition. Pads bufPosition_ - oldPos characters.
|
||||
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
|
||||
}
|
||||
|
||||
if (size_t(buf_.size()) < bufPosition_ + count)
|
||||
{
|
||||
enlargeBuffer(bufPosition_ - oldPos + count);
|
||||
}
|
||||
|
||||
register char* bufPtr = &buf_[bufPosition_];
|
||||
register const char* dataPtr = reinterpret_cast<const char*>(data);
|
||||
register size_t i = count;
|
||||
while (i--) *bufPtr++ = *dataPtr++;
|
||||
|
||||
bufPosition_ += count;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -92,137 +33,14 @@ Foam::OPstream::OPstream
|
||||
const commsTypes commsType,
|
||||
const int toProcNo,
|
||||
const label bufSize,
|
||||
const int tag,
|
||||
streamFormat format,
|
||||
versionNumber version
|
||||
)
|
||||
:
|
||||
Pstream(commsType, bufSize),
|
||||
Ostream(format, version),
|
||||
toProcNo_(toProcNo)
|
||||
{
|
||||
setOpened();
|
||||
setGood();
|
||||
|
||||
if (!bufSize)
|
||||
{
|
||||
buf_.setSize(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::OPstream::write(const token&)
|
||||
{
|
||||
notImplemented("Ostream& OPstream::write(const token&)");
|
||||
setBad();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OPstream::write(const char c)
|
||||
{
|
||||
if (!isspace(c))
|
||||
{
|
||||
writeToBuffer(c);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OPstream::write(const char* str)
|
||||
{
|
||||
word nonWhiteChars(string::validate<word>(str));
|
||||
|
||||
if (nonWhiteChars.size() == 1)
|
||||
{
|
||||
return write(nonWhiteChars.c_str()[1]);
|
||||
}
|
||||
else if (nonWhiteChars.size())
|
||||
{
|
||||
return write(nonWhiteChars);
|
||||
}
|
||||
else
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OPstream::write(const word& str)
|
||||
{
|
||||
write(char(token::WORD));
|
||||
|
||||
size_t len = str.size();
|
||||
writeToBuffer(len);
|
||||
writeToBuffer(str.c_str(), len + 1, 1);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OPstream::write(const string& str)
|
||||
{
|
||||
write(char(token::STRING));
|
||||
|
||||
size_t len = str.size();
|
||||
writeToBuffer(len);
|
||||
writeToBuffer(str.c_str(), len + 1, 1);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OPstream::writeQuoted(const std::string& str, const bool)
|
||||
{
|
||||
write(char(token::STRING));
|
||||
|
||||
size_t len = str.size();
|
||||
writeToBuffer(len);
|
||||
writeToBuffer(str.c_str(), len + 1, 1);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OPstream::write(const label val)
|
||||
{
|
||||
write(char(token::LABEL));
|
||||
writeToBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OPstream::write(const floatScalar val)
|
||||
{
|
||||
write(char(token::FLOAT_SCALAR));
|
||||
writeToBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OPstream::write(const doubleScalar val)
|
||||
{
|
||||
write(char(token::DOUBLE_SCALAR));
|
||||
writeToBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OPstream::write(const char* data, std::streamsize count)
|
||||
{
|
||||
if (format() != BINARY)
|
||||
{
|
||||
FatalErrorIn("Ostream::write(const char*, std::streamsize)")
|
||||
<< "stream format not binary"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
writeToBuffer(data, count, 8);
|
||||
|
||||
return *this;
|
||||
}
|
||||
UOPstream(commsType, toProcNo, buf_, tag, true, format, version)
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -38,7 +38,7 @@ SourceFiles
|
||||
#ifndef OPstream_H
|
||||
#define OPstream_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "UOPstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -52,25 +52,8 @@ namespace Foam
|
||||
class OPstream
|
||||
:
|
||||
public Pstream,
|
||||
public Ostream
|
||||
public UOPstream
|
||||
{
|
||||
// Private data
|
||||
|
||||
int toProcNo_;
|
||||
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Write a T to the transfer buffer
|
||||
template<class T>
|
||||
inline void writeToBuffer(const T&);
|
||||
|
||||
//- Write a char to the transfer buffer
|
||||
inline void writeToBuffer(const char&);
|
||||
|
||||
//- Write data to the transfer buffer
|
||||
inline void writeToBuffer(const void* data, size_t count, size_t align);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -83,126 +66,11 @@ public:
|
||||
const commsTypes commsType,
|
||||
const int toProcNo,
|
||||
const label bufSize = 0,
|
||||
const int tag = UPstream::msgType(),
|
||||
streamFormat format=BINARY,
|
||||
versionNumber version=currentVersion
|
||||
);
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
~OPstream();
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Inquiry
|
||||
|
||||
//- Return flags of output stream
|
||||
ios_base::fmtflags flags() const
|
||||
{
|
||||
return ios_base::fmtflags(0);
|
||||
}
|
||||
|
||||
|
||||
// Write functions
|
||||
|
||||
//- Write given buffer to given processor
|
||||
static bool write
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int toProcNo,
|
||||
const char* buf,
|
||||
const std::streamsize bufSize
|
||||
);
|
||||
|
||||
//- Write next token to stream
|
||||
Ostream& write(const token&);
|
||||
|
||||
//- Write character
|
||||
Ostream& write(const char);
|
||||
|
||||
//- Write character string
|
||||
Ostream& write(const char*);
|
||||
|
||||
//- Write word
|
||||
Ostream& write(const word&);
|
||||
|
||||
//- Write string
|
||||
Ostream& write(const string&);
|
||||
|
||||
//- Write std::string surrounded by quotes.
|
||||
// Optional write without quotes.
|
||||
Ostream& writeQuoted
|
||||
(
|
||||
const std::string&,
|
||||
const bool quoted=true
|
||||
);
|
||||
|
||||
//- Write label
|
||||
Ostream& write(const label);
|
||||
|
||||
//- Write floatScalar
|
||||
Ostream& write(const floatScalar);
|
||||
|
||||
//- Write doubleScalar
|
||||
Ostream& write(const doubleScalar);
|
||||
|
||||
//- Write binary block
|
||||
Ostream& write(const char*, std::streamsize);
|
||||
|
||||
//- Add indentation characters
|
||||
void indent()
|
||||
{}
|
||||
|
||||
|
||||
// Stream state functions
|
||||
|
||||
//- Flush stream
|
||||
void flush()
|
||||
{}
|
||||
|
||||
//- Add newline and flush stream
|
||||
void endl()
|
||||
{}
|
||||
|
||||
//- Get width of output field
|
||||
int width() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- Set width of output field (and return old width)
|
||||
int width(const int)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- Get precision of output field
|
||||
int precision() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- Set precision of output field (and return old precision)
|
||||
int precision(const int)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Set flags of stream
|
||||
ios_base::fmtflags flags(const ios_base::fmtflags)
|
||||
{
|
||||
return ios_base::fmtflags(0);
|
||||
}
|
||||
|
||||
|
||||
// Print
|
||||
|
||||
//- Print description of IOstream to Ostream
|
||||
void print(Ostream&) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -25,226 +25,16 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Pstream.H"
|
||||
#include "debug.H"
|
||||
#include "dictionary.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
defineTypeNameAndDebug(Foam::Pstream, 0);
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum<Foam::Pstream::commsTypes, 3>::names[] =
|
||||
{
|
||||
"blocking",
|
||||
"scheduled",
|
||||
"nonBlocking"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum<Foam::Pstream::commsTypes, 3>
|
||||
Foam::Pstream::commsTypeNames;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::Pstream::setParRun()
|
||||
{
|
||||
parRun_ = true;
|
||||
|
||||
Pout.prefix() = '[' + name(myProcNo()) + "] ";
|
||||
Perr.prefix() = '[' + name(myProcNo()) + "] ";
|
||||
}
|
||||
|
||||
|
||||
void Foam::Pstream::calcLinearComm(const label nProcs)
|
||||
{
|
||||
linearCommunication_.setSize(nProcs);
|
||||
|
||||
// Master
|
||||
labelList belowIDs(nProcs - 1);
|
||||
forAll(belowIDs, i)
|
||||
{
|
||||
belowIDs[i] = i + 1;
|
||||
}
|
||||
|
||||
linearCommunication_[0] = commsStruct
|
||||
(
|
||||
nProcs,
|
||||
0,
|
||||
-1,
|
||||
belowIDs,
|
||||
labelList(0)
|
||||
);
|
||||
|
||||
// Slaves. Have no below processors, only communicate up to master
|
||||
for (label procID = 1; procID < nProcs; procID++)
|
||||
{
|
||||
linearCommunication_[procID] = commsStruct
|
||||
(
|
||||
nProcs,
|
||||
procID,
|
||||
0,
|
||||
labelList(0),
|
||||
labelList(0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Append my children (and my children children etc.) to allReceives.
|
||||
void Foam::Pstream::collectReceives
|
||||
(
|
||||
const label procID,
|
||||
const List<DynamicList<label> >& receives,
|
||||
DynamicList<label>& allReceives
|
||||
)
|
||||
{
|
||||
const DynamicList<label>& myChildren = receives[procID];
|
||||
|
||||
forAll(myChildren, childI)
|
||||
{
|
||||
allReceives.append(myChildren[childI]);
|
||||
collectReceives(myChildren[childI], receives, allReceives);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Tree like schedule. For 8 procs:
|
||||
// (level 0)
|
||||
// 0 receives from 1
|
||||
// 2 receives from 3
|
||||
// 4 receives from 5
|
||||
// 6 receives from 7
|
||||
// (level 1)
|
||||
// 0 receives from 2
|
||||
// 4 receives from 6
|
||||
// (level 2)
|
||||
// 0 receives from 4
|
||||
//
|
||||
// The sends/receives for all levels are collected per processor (one send per
|
||||
// processor; multiple receives possible) creating a table:
|
||||
//
|
||||
// So per processor:
|
||||
// proc receives from sends to
|
||||
// ---- ------------- --------
|
||||
// 0 1,2,4 -
|
||||
// 1 - 0
|
||||
// 2 3 0
|
||||
// 3 - 2
|
||||
// 4 5 0
|
||||
// 5 - 4
|
||||
// 6 7 4
|
||||
// 7 - 6
|
||||
void Foam::Pstream::calcTreeComm(label nProcs)
|
||||
{
|
||||
label nLevels = 1;
|
||||
while ((1 << nLevels) < nProcs)
|
||||
{
|
||||
nLevels++;
|
||||
}
|
||||
|
||||
List<DynamicList<label> > receives(nProcs);
|
||||
labelList sends(nProcs, -1);
|
||||
|
||||
// Info<< "Using " << nLevels << " communication levels" << endl;
|
||||
|
||||
label offset = 2;
|
||||
label childOffset = offset/2;
|
||||
|
||||
for (label level = 0; level < nLevels; level++)
|
||||
{
|
||||
label receiveID = 0;
|
||||
while (receiveID < nProcs)
|
||||
{
|
||||
// Determine processor that sends and we receive from
|
||||
label sendID = receiveID + childOffset;
|
||||
|
||||
if (sendID < nProcs)
|
||||
{
|
||||
receives[receiveID].append(sendID);
|
||||
sends[sendID] = receiveID;
|
||||
}
|
||||
|
||||
receiveID += offset;
|
||||
}
|
||||
|
||||
offset <<= 1;
|
||||
childOffset <<= 1;
|
||||
}
|
||||
|
||||
// For all processors find the processors it receives data from
|
||||
// (and the processors they receive data from etc.)
|
||||
List<DynamicList<label> > allReceives(nProcs);
|
||||
for (label procID = 0; procID < nProcs; procID++)
|
||||
{
|
||||
collectReceives(procID, receives, allReceives[procID]);
|
||||
}
|
||||
|
||||
|
||||
treeCommunication_.setSize(nProcs);
|
||||
|
||||
for (label procID = 0; procID < nProcs; procID++)
|
||||
{
|
||||
treeCommunication_[procID] = commsStruct
|
||||
(
|
||||
nProcs,
|
||||
procID,
|
||||
sends[procID],
|
||||
receives[procID].shrink(),
|
||||
allReceives[procID].shrink()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Callback from Pstream::init() : initialize linear and tree communication
|
||||
// schedules now that nProcs is known.
|
||||
void Foam::Pstream::initCommunicationSchedule()
|
||||
{
|
||||
calcLinearComm(nProcs());
|
||||
calcTreeComm(nProcs());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// Initialise my process number to 0 (the master)
|
||||
int Foam::Pstream::myProcNo_(0);
|
||||
|
||||
// By default this is not a parallel run
|
||||
bool Foam::Pstream::parRun_(false);
|
||||
|
||||
// List of process IDs
|
||||
Foam::List<int> Foam::Pstream::procIDs_(1, 0);
|
||||
|
||||
// Standard transfer message type
|
||||
int Foam::Pstream::msgType_(1);
|
||||
|
||||
// Linear communication schedule
|
||||
Foam::List<Foam::Pstream::commsStruct> Foam::Pstream::linearCommunication_(0);
|
||||
|
||||
// Multi level communication schedule
|
||||
Foam::List<Foam::Pstream::commsStruct> Foam::Pstream::treeCommunication_(0);
|
||||
|
||||
// Should compact transfer be used in which floats replace doubles
|
||||
// reducing the bandwidth requirement at the expense of some loss
|
||||
// in accuracy
|
||||
bool Foam::Pstream::floatTransfer
|
||||
(
|
||||
debug::optimisationSwitch("floatTransfer", 0)
|
||||
);
|
||||
|
||||
// Number of processors at which the reduce algorithm changes from linear to
|
||||
// tree
|
||||
int Foam::Pstream::nProcsSimpleSum
|
||||
(
|
||||
debug::optimisationSwitch("nProcsSimpleSum", 16)
|
||||
);
|
||||
|
||||
// Default commsType
|
||||
Foam::Pstream::commsTypes Foam::Pstream::defaultCommsType
|
||||
(
|
||||
commsTypeNames.read(debug::optimisationSwitches().lookup("commsType"))
|
||||
);
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -30,22 +30,18 @@ Description
|
||||
|
||||
SourceFiles
|
||||
Pstream.C
|
||||
PstreamsPrint.C
|
||||
PstreamCommsStruct.C
|
||||
gatherScatter.C
|
||||
combineGatherScatter.C
|
||||
gatherScatterList.C
|
||||
exchange.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Pstream_H
|
||||
#define Pstream_H
|
||||
|
||||
#include "labelList.H"
|
||||
#include "UPstream.H"
|
||||
#include "DynamicList.H"
|
||||
#include "HashTable.H"
|
||||
#include "string.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -57,162 +53,16 @@ namespace Foam
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class Pstream
|
||||
:
|
||||
public UPstream
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Types of communications
|
||||
enum commsTypes
|
||||
{
|
||||
blocking,
|
||||
scheduled,
|
||||
nonBlocking
|
||||
};
|
||||
|
||||
static const NamedEnum<commsTypes, 3> commsTypeNames;
|
||||
|
||||
//- Structure for communicating between processors
|
||||
class commsStruct
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- procID of above processor
|
||||
label above_;
|
||||
|
||||
//- procIDs of processors directly below me
|
||||
labelList below_;
|
||||
|
||||
//- procIDs of all processors below (so not just directly below)
|
||||
labelList allBelow_;
|
||||
|
||||
//- procIDs of all processors not below. (inverse set of allBelow_
|
||||
// and minus myProcNo)
|
||||
labelList allNotBelow_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
commsStruct();
|
||||
|
||||
//- Construct from components
|
||||
commsStruct
|
||||
(
|
||||
const label,
|
||||
const labelList&,
|
||||
const labelList&,
|
||||
const labelList&
|
||||
);
|
||||
|
||||
//- Construct from components; construct allNotBelow_
|
||||
commsStruct
|
||||
(
|
||||
const label nProcs,
|
||||
const label myProcID,
|
||||
const label,
|
||||
const labelList&,
|
||||
const labelList&
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
label above() const
|
||||
{
|
||||
return above_;
|
||||
}
|
||||
|
||||
const labelList& below() const
|
||||
{
|
||||
return below_;
|
||||
}
|
||||
|
||||
const labelList& allBelow() const
|
||||
{
|
||||
return allBelow_;
|
||||
}
|
||||
|
||||
const labelList& allNotBelow() const
|
||||
{
|
||||
return allNotBelow_;
|
||||
}
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
bool operator==(const commsStruct&) const;
|
||||
|
||||
bool operator!=(const commsStruct&) const;
|
||||
|
||||
|
||||
// Ostream Operator
|
||||
|
||||
friend Ostream& operator<<(Ostream&, const commsStruct&);
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
static int myProcNo_;
|
||||
static bool parRun_;
|
||||
|
||||
static List<int> procIDs_;
|
||||
static int msgType_;
|
||||
|
||||
static List<commsStruct> linearCommunication_;
|
||||
static List<commsStruct> treeCommunication_;
|
||||
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Set data for parallel running
|
||||
static void setParRun();
|
||||
|
||||
//- Calculate linear communication schedule
|
||||
static void calcLinearComm(const label nProcs);
|
||||
|
||||
//- Calculate tree communication schedule
|
||||
static void calcTreeComm(const label nProcs);
|
||||
|
||||
//- Helper function for tree communication schedule determination
|
||||
// Collects all processorIDs below a processor
|
||||
static void collectReceives
|
||||
(
|
||||
const label procID,
|
||||
const List<DynamicList<label> >& receives,
|
||||
DynamicList<label>& allReceives
|
||||
);
|
||||
|
||||
//- Initialize all communication schedules. Callback from
|
||||
// Pstream::init()
|
||||
static void initCommunicationSchedule();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Communications type of this stream
|
||||
commsTypes commsType_;
|
||||
|
||||
//- Transfer buffer
|
||||
List<char> buf_;
|
||||
|
||||
//- Current buffer read/write location
|
||||
int bufPosition_;
|
||||
|
||||
|
||||
// Protected member functions
|
||||
|
||||
//- Increase the size of the transfer buffer
|
||||
inline void enlargeBuffer(size_t count);
|
||||
|
||||
DynamicList<char> buf_;
|
||||
|
||||
public:
|
||||
|
||||
@ -220,21 +70,6 @@ public:
|
||||
ClassName("Pstream");
|
||||
|
||||
|
||||
// Static data
|
||||
|
||||
//- Should compact transfer be used in which floats replace doubles
|
||||
// reducing the bandwidth requirement at the expense of some loss
|
||||
// in accuracy
|
||||
static bool floatTransfer;
|
||||
|
||||
//- Number of processors at which the sum algorithm changes from linear
|
||||
// to tree
|
||||
static int nProcsSimpleSum;
|
||||
|
||||
//- Default commsType
|
||||
static commsTypes defaultCommsType;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct given optional buffer size
|
||||
@ -244,151 +79,16 @@ public:
|
||||
const label bufSize = 0
|
||||
)
|
||||
:
|
||||
commsType_(commsType),
|
||||
bufPosition_(0)
|
||||
UPstream(commsType),
|
||||
buf_(0)
|
||||
{
|
||||
if (bufSize)
|
||||
{
|
||||
buf_.setSize(bufSize + 2*sizeof(scalar) + 1);
|
||||
buf_.setCapacity(bufSize + 2*sizeof(scalar) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Add the valid option this type of communications library
|
||||
// adds/requires on the command line
|
||||
static void addValidParOptions(HashTable<string>& validParOptions);
|
||||
|
||||
//- Initialisation function called from main
|
||||
// Spawns slave processes and initialises inter-communication
|
||||
static bool init(int& argc, char**& argv);
|
||||
|
||||
//- Non-blocking comms: wait until all have finished.
|
||||
static void waitRequests();
|
||||
|
||||
//- Non-blocking comms: has request i finished?
|
||||
static bool finishedRequest(const label i);
|
||||
|
||||
//- Is this a parallel run?
|
||||
static bool parRun()
|
||||
{
|
||||
return parRun_;
|
||||
}
|
||||
|
||||
//- Number of processes in parallel run
|
||||
static label nProcs()
|
||||
{
|
||||
return procIDs_.size();
|
||||
}
|
||||
|
||||
//- Am I the master process
|
||||
static bool master()
|
||||
{
|
||||
return myProcNo_ == 0;
|
||||
}
|
||||
|
||||
//- Process index of the master
|
||||
static int masterNo()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- Number of this process (starting from masterNo() = 0)
|
||||
static int myProcNo()
|
||||
{
|
||||
return myProcNo_;
|
||||
}
|
||||
|
||||
//- Process IDs
|
||||
static const List<int>& procIDs()
|
||||
{
|
||||
return procIDs_;
|
||||
}
|
||||
|
||||
//- Process ID of given process index
|
||||
static int procID(int procNo)
|
||||
{
|
||||
return procIDs_[procNo];
|
||||
}
|
||||
|
||||
//- Process index of first slave
|
||||
static int firstSlave()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
//- Process index of last slave
|
||||
static int lastSlave()
|
||||
{
|
||||
return nProcs() - 1;
|
||||
}
|
||||
|
||||
//- Communication schedule for linear all-to-master (proc 0)
|
||||
static const List<commsStruct>& linearCommunication()
|
||||
{
|
||||
return linearCommunication_;
|
||||
}
|
||||
|
||||
//- Communication schedule for tree all-to-master (proc 0)
|
||||
static const List<commsStruct>& treeCommunication()
|
||||
{
|
||||
return treeCommunication_;
|
||||
}
|
||||
|
||||
//- Message tag of standard messages
|
||||
static int& msgType()
|
||||
{
|
||||
return msgType_;
|
||||
}
|
||||
|
||||
|
||||
//- Get the communications type of the stream
|
||||
commsTypes commsType() const
|
||||
{
|
||||
return commsType_;
|
||||
}
|
||||
|
||||
//- Set the communications type of the stream
|
||||
commsTypes commsType(const commsTypes ct)
|
||||
{
|
||||
commsTypes oldCommsType = commsType_;
|
||||
commsType_ = ct;
|
||||
return oldCommsType;
|
||||
}
|
||||
|
||||
//- Transfer buffer
|
||||
const List<char>& buf() const
|
||||
{
|
||||
return buf_;
|
||||
}
|
||||
|
||||
//- Transfer buffer
|
||||
List<char>& buf()
|
||||
{
|
||||
return buf_;
|
||||
}
|
||||
|
||||
//- Current buffer read/write location
|
||||
int bufPosition() const
|
||||
{
|
||||
return bufPosition_;
|
||||
}
|
||||
|
||||
//- Current buffer read/write location
|
||||
int& bufPosition()
|
||||
{
|
||||
return bufPosition_;
|
||||
}
|
||||
|
||||
|
||||
//- Exit program
|
||||
static void exit(int errnum = 1);
|
||||
|
||||
//- Abort program
|
||||
static void abort();
|
||||
|
||||
|
||||
// Gather and scatter
|
||||
|
||||
//- Gather data. Apply bop to combine Value
|
||||
@ -501,8 +201,8 @@ public:
|
||||
|
||||
|
||||
// Gather/scatter keeping the individual processor data separate.
|
||||
// Values is a List of size Pstream::nProcs() where
|
||||
// Values[Pstream::myProcNo()] is the data for the current processor.
|
||||
// Values is a List of size UPstream::nProcs() where
|
||||
// Values[UPstream::myProcNo()] is the data for the current processor.
|
||||
|
||||
//- Gather data but keep individual values separate
|
||||
template <class T>
|
||||
@ -527,18 +227,27 @@ public:
|
||||
//- Like above but switches between linear/tree communication
|
||||
template <class T>
|
||||
static void scatterList(List<T>& Values);
|
||||
|
||||
|
||||
// Exchange
|
||||
|
||||
//- Exchange data. Sends sendData, receives into recvData, sets
|
||||
// sizes (not bytes). sizes[p0][p1] is what processor p0 has
|
||||
// sent to p1. Continuous data only.
|
||||
// If block=true will wait for all transfers to finish.
|
||||
template <class Container, class T>
|
||||
static void exchange
|
||||
(
|
||||
const List<Container >&,
|
||||
List<Container >&,
|
||||
labelListList& sizes,
|
||||
const int tag = UPstream::msgType(),
|
||||
const bool block = true
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline void Pstream::enlargeBuffer(size_t count)
|
||||
{
|
||||
buf_.setSize(max(int(buf_.size() + count), 2*buf_.size()));
|
||||
}
|
||||
|
||||
|
||||
Ostream& operator<<(Ostream&, const Pstream::commsStruct&);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
@ -549,9 +258,9 @@ Ostream& operator<<(Ostream&, const Pstream::commsStruct&);
|
||||
# include "gatherScatter.C"
|
||||
# include "combineGatherScatter.C"
|
||||
# include "gatherScatterList.C"
|
||||
# include "exchange.C"
|
||||
#endif
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
117
src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C
Normal file
117
src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C
Normal file
@ -0,0 +1,117 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "PstreamBuffers.H"
|
||||
|
||||
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
DynamicList<char> PstreamBuffers::nullBuf(0);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::PstreamBuffers::PstreamBuffers
|
||||
(
|
||||
const UPstream::commsTypes commsType,
|
||||
const int tag,
|
||||
IOstream::streamFormat format,
|
||||
IOstream::versionNumber version
|
||||
)
|
||||
:
|
||||
commsType_(commsType),
|
||||
tag_(tag),
|
||||
format_(format),
|
||||
version_(version),
|
||||
sendBuf_(UPstream::nProcs()),
|
||||
recvBuf_(UPstream::nProcs()),
|
||||
finishedSendsCalled_(false)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::PstreamBuffers::finishedSends(const bool block)
|
||||
{
|
||||
finishedSendsCalled_ = true;
|
||||
|
||||
if (commsType_ == UPstream::nonBlocking)
|
||||
{
|
||||
labelListList sizes;
|
||||
Pstream::exchange<DynamicList<char>, char>
|
||||
(
|
||||
sendBuf_,
|
||||
recvBuf_,
|
||||
sizes,
|
||||
tag_,
|
||||
block
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::PstreamBuffers::finishedSends(labelListList& sizes, const bool block)
|
||||
{
|
||||
finishedSendsCalled_ = true;
|
||||
|
||||
if (commsType_ == UPstream::nonBlocking)
|
||||
{
|
||||
labelListList sizes;
|
||||
labelListList send,recv;
|
||||
|
||||
Pstream::exchange<DynamicList<char>, char>
|
||||
(
|
||||
sendBuf_,
|
||||
recvBuf_,
|
||||
sizes,
|
||||
tag_,
|
||||
block
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
sizes.setSize(UPstream::nProcs());
|
||||
labelList& nsTransPs = sizes[UPstream::myProcNo()];
|
||||
nsTransPs.setSize(UPstream::nProcs());
|
||||
|
||||
forAll(sendBuf_, procI)
|
||||
{
|
||||
nsTransPs[procI] = sendBuf_[procI].size();
|
||||
}
|
||||
|
||||
// Send sizes across.
|
||||
int oldTag = UPstream::msgType();
|
||||
UPstream::msgType() = tag_;
|
||||
combineReduce(sizes, UPstream::listEq());
|
||||
UPstream::msgType() = oldTag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
155
src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H
Normal file
155
src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H
Normal file
@ -0,0 +1,155 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::PstreamBuffers
|
||||
|
||||
Description
|
||||
Buffers for inter-processor communications streams (UOPstream, UIPstream).
|
||||
|
||||
Use UOPstream to stream data into buffers, call finishedSends() to
|
||||
notify that data is in buffers and then use IUPstream to get data out
|
||||
of received buffers. Works with both blocking and nonBlocking. Does
|
||||
not make much sense with scheduled since there you would not need these
|
||||
explicit buffers.
|
||||
|
||||
Example usage:
|
||||
|
||||
PstreamBuffers pBuffers(Pstream::nonBlocking);
|
||||
|
||||
for (label procI = 0; procI < Pstream::nProcs(); procI++)
|
||||
{
|
||||
if (procI != Pstream::myProcNo())
|
||||
{
|
||||
someObject vals;
|
||||
|
||||
UOPstream str(procI, pBuffers);
|
||||
str << vals;
|
||||
}
|
||||
}
|
||||
|
||||
pBuffers.finishedSends(); // no-op for blocking
|
||||
|
||||
for (label procI = 0; procI < Pstream::nProcs(); procI++)
|
||||
{
|
||||
if (procI != Pstream::myProcNo())
|
||||
{
|
||||
UIPstream str(procI, pBuffers);
|
||||
someObject vals(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SourceFiles
|
||||
PstreamBuffers.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Pstream.H"
|
||||
|
||||
#ifndef PstreamBuffers_H
|
||||
#define PstreamBuffers_H
|
||||
|
||||
#include "DynamicList.H"
|
||||
#include "UPstream.H"
|
||||
#include "IOstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class PstreamBuffers Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class PstreamBuffers
|
||||
{
|
||||
friend class UOPstream;
|
||||
friend class UIPstream;
|
||||
|
||||
// Private data
|
||||
|
||||
//- Communications type of this stream
|
||||
const UPstream::commsTypes commsType_;
|
||||
|
||||
const int tag_;
|
||||
|
||||
const IOstream::streamFormat format_;
|
||||
|
||||
const IOstream::versionNumber version_;
|
||||
|
||||
//- send buffer
|
||||
List<DynamicList<char> > sendBuf_;
|
||||
|
||||
//- receive buffer
|
||||
List<DynamicList<char> > recvBuf_;
|
||||
|
||||
bool finishedSendsCalled_;
|
||||
|
||||
// Private member functions
|
||||
|
||||
public:
|
||||
|
||||
// Static data
|
||||
|
||||
static DynamicList<char> nullBuf;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct given comms type,
|
||||
// write format and IO version
|
||||
PstreamBuffers
|
||||
(
|
||||
const UPstream::commsTypes commsType,
|
||||
const int tag = UPstream::msgType(),
|
||||
IOstream::streamFormat format=IOstream::BINARY,
|
||||
IOstream::versionNumber version=IOstream::currentVersion
|
||||
);
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Mark all sends as having been done. This will start receives
|
||||
// in non-blocking mode. If block will wait for all transfers to
|
||||
// finish (only relevant for nonBlocking mode)
|
||||
void finishedSends(const bool block = true);
|
||||
|
||||
//- Mark all sends as having been done. Same as above but also returns
|
||||
// sizes (bytes) transferred.
|
||||
void finishedSends(labelListList& sizes, const bool block = true);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -23,7 +23,7 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
InClass
|
||||
Foam::Pstream
|
||||
Foam
|
||||
|
||||
Description
|
||||
Combination-Reduction operation for a parallel run. The
|
||||
@ -37,6 +37,7 @@ Description
|
||||
#ifndef PstreamCombineReduceOps_H
|
||||
#define PstreamCombineReduceOps_H
|
||||
|
||||
#include "UPstream.H"
|
||||
#include "Pstream.H"
|
||||
#include "ops.H"
|
||||
|
||||
@ -50,7 +51,7 @@ namespace Foam
|
||||
template <class T, class CombineOp>
|
||||
void combineReduce
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
T& Value,
|
||||
const CombineOp& cop
|
||||
)
|
||||
@ -63,15 +64,15 @@ void combineReduce
|
||||
template <class T, class CombineOp>
|
||||
void combineReduce(T& Value, const CombineOp& cop)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
Pstream::combineGather(Pstream::linearCommunication(), Value, cop);
|
||||
Pstream::combineScatter(Pstream::linearCommunication(), Value);
|
||||
Pstream::combineGather(UPstream::linearCommunication(), Value, cop);
|
||||
Pstream::combineScatter(UPstream::linearCommunication(), Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Pstream::combineGather(Pstream::treeCommunication(), Value, cop);
|
||||
Pstream::combineScatter(Pstream::treeCommunication(), Value);
|
||||
Pstream::combineGather(UPstream::treeCommunication(), Value, cop);
|
||||
Pstream::combineScatter(UPstream::treeCommunication(), Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ namespace Foam
|
||||
template <class T, class BinaryOp>
|
||||
void reduce
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
T& Value,
|
||||
const BinaryOp& bop
|
||||
)
|
||||
@ -59,13 +59,13 @@ void reduce
|
||||
const BinaryOp& bop
|
||||
)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
reduce(Pstream::linearCommunication(), Value, bop);
|
||||
reduce(UPstream::linearCommunication(), Value, bop);
|
||||
}
|
||||
else
|
||||
{
|
||||
reduce(Pstream::treeCommunication(), Value, bop);
|
||||
reduce(UPstream::treeCommunication(), Value, bop);
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,13 +80,13 @@ T returnReduce
|
||||
{
|
||||
T WorkValue(Value);
|
||||
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
reduce(Pstream::linearCommunication(), WorkValue, bop);
|
||||
reduce(UPstream::linearCommunication(), WorkValue, bop);
|
||||
}
|
||||
else
|
||||
{
|
||||
reduce(Pstream::treeCommunication(), WorkValue, bop);
|
||||
reduce(UPstream::treeCommunication(), WorkValue, bop);
|
||||
}
|
||||
|
||||
return WorkValue;
|
||||
|
||||
322
src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C
Normal file
322
src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C
Normal file
@ -0,0 +1,322 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "UIPstream.H"
|
||||
#include "int.H"
|
||||
#include "token.H"
|
||||
#include <cctype>
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::UIPstream::checkEof()
|
||||
{
|
||||
if (externalBufPosition_ == messageSize_)
|
||||
{
|
||||
setEof();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UIPstream::readFromBuffer(T& t)
|
||||
{
|
||||
const size_t align = sizeof(T);
|
||||
externalBufPosition_ = align + ((externalBufPosition_ - 1) & ~(align - 1));
|
||||
|
||||
t = reinterpret_cast<T&>(externalBuf_[externalBufPosition_]);
|
||||
externalBufPosition_ += sizeof(T);
|
||||
checkEof();
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::UIPstream::readFromBuffer
|
||||
(
|
||||
void* data,
|
||||
size_t count,
|
||||
size_t align
|
||||
)
|
||||
{
|
||||
if (align > 1)
|
||||
{
|
||||
externalBufPosition_ =
|
||||
align
|
||||
+ ((externalBufPosition_ - 1) & ~(align - 1));
|
||||
}
|
||||
|
||||
register const char* bufPtr = &externalBuf_[externalBufPosition_];
|
||||
register char* dataPtr = reinterpret_cast<char*>(data);
|
||||
register size_t i = count;
|
||||
while (i--) *dataPtr++ = *bufPtr++;
|
||||
externalBufPosition_ += count;
|
||||
checkEof();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::UIPstream::~UIPstream()
|
||||
{
|
||||
if (externalBufPosition_ < messageSize_)
|
||||
{
|
||||
FatalErrorIn("UIPstream::~UIPstream()")
|
||||
<< "Message not fully consumed. messageSize:" << messageSize_
|
||||
<< " bytes of which only " << externalBufPosition_
|
||||
<< " consumed." << Foam::abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Istream& Foam::UIPstream::read(token& t)
|
||||
{
|
||||
// Return the put back token if it exists
|
||||
if (Istream::getBack(t))
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
char c;
|
||||
|
||||
// return on error
|
||||
if (!read(c))
|
||||
{
|
||||
t.setBad();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Set the line number of this token to the current stream line number
|
||||
t.lineNumber() = lineNumber();
|
||||
|
||||
// Analyse input starting with this character.
|
||||
switch (c)
|
||||
{
|
||||
// Punctuation
|
||||
case token::END_STATEMENT :
|
||||
case token::BEGIN_LIST :
|
||||
case token::END_LIST :
|
||||
case token::BEGIN_SQR :
|
||||
case token::END_SQR :
|
||||
case token::BEGIN_BLOCK :
|
||||
case token::END_BLOCK :
|
||||
case token::COLON :
|
||||
case token::COMMA :
|
||||
case token::ASSIGN :
|
||||
case token::ADD :
|
||||
case token::SUBTRACT :
|
||||
case token::MULTIPLY :
|
||||
case token::DIVIDE :
|
||||
{
|
||||
t = token::punctuationToken(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Word
|
||||
case token::WORD :
|
||||
{
|
||||
word* pval = new word;
|
||||
if (read(*pval))
|
||||
{
|
||||
if (token::compound::isCompound(*pval))
|
||||
{
|
||||
t = token::compound::New(*pval, *this).ptr();
|
||||
delete pval;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = pval;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pval;
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// String
|
||||
case token::STRING :
|
||||
{
|
||||
string* pval = new string;
|
||||
if (read(*pval))
|
||||
{
|
||||
t = pval;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pval;
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Label
|
||||
case token::LABEL :
|
||||
{
|
||||
label val;
|
||||
if (read(val))
|
||||
{
|
||||
t = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// floatScalar
|
||||
case token::FLOAT_SCALAR :
|
||||
{
|
||||
floatScalar val;
|
||||
if (read(val))
|
||||
{
|
||||
t = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// doubleScalar
|
||||
case token::DOUBLE_SCALAR :
|
||||
{
|
||||
doubleScalar val;
|
||||
if (read(val))
|
||||
{
|
||||
t = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.setBad();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Character (returned as a single character word) or error
|
||||
default:
|
||||
{
|
||||
if (isalpha(c))
|
||||
{
|
||||
t = word(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
setBad();
|
||||
t.setBad();
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::UIPstream::read(char& c)
|
||||
{
|
||||
c = externalBuf_[externalBufPosition_];
|
||||
externalBufPosition_++;
|
||||
checkEof();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::UIPstream::read(word& str)
|
||||
{
|
||||
size_t len;
|
||||
readFromBuffer(len);
|
||||
str = &externalBuf_[externalBufPosition_];
|
||||
externalBufPosition_ += len + 1;
|
||||
checkEof();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::UIPstream::read(string& str)
|
||||
{
|
||||
size_t len;
|
||||
readFromBuffer(len);
|
||||
str = &externalBuf_[externalBufPosition_];
|
||||
externalBufPosition_ += len + 1;
|
||||
checkEof();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::UIPstream::read(label& val)
|
||||
{
|
||||
readFromBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::UIPstream::read(floatScalar& val)
|
||||
{
|
||||
readFromBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::UIPstream::read(doubleScalar& val)
|
||||
{
|
||||
readFromBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::UIPstream::read(char* data, std::streamsize count)
|
||||
{
|
||||
if (format() != BINARY)
|
||||
{
|
||||
FatalErrorIn("UIPstream::read(char*, std::streamsize)")
|
||||
<< "stream format not binary"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
readFromBuffer(data, count, 8);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::UIPstream::rewind()
|
||||
{
|
||||
externalBufPosition_ = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Foam::UIPstream::print(Ostream& os) const
|
||||
{
|
||||
os << "Reading from processor " << fromProcNo_
|
||||
<< " to processor " << myProcNo() << Foam::endl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
187
src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H
Normal file
187
src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H
Normal file
@ -0,0 +1,187 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::UIPstream
|
||||
|
||||
Description
|
||||
Input inter-processor communications stream operating on external
|
||||
buffer.
|
||||
|
||||
SourceFiles
|
||||
UIPstream.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Pstream.H"
|
||||
|
||||
#ifndef UIPstream_H
|
||||
#define UIPstream_H
|
||||
|
||||
#include "UPstream.H"
|
||||
#include "Istream.H"
|
||||
#include "PstreamBuffers.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class UIPstream Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class UIPstream
|
||||
:
|
||||
public UPstream,
|
||||
public Istream
|
||||
{
|
||||
// Private data
|
||||
|
||||
int fromProcNo_;
|
||||
|
||||
DynamicList<char>& externalBuf_;
|
||||
|
||||
label externalBufPosition_;
|
||||
|
||||
const int tag_;
|
||||
|
||||
label messageSize_;
|
||||
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Check the bufferPosition against messageSize_ for EOF
|
||||
inline void checkEof();
|
||||
|
||||
//- Read a T from the transfer buffer
|
||||
template<class T>
|
||||
inline void readFromBuffer(T&);
|
||||
|
||||
//- Read data from the transfer buffer
|
||||
inline void readFromBuffer(void* data, size_t count, size_t align);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct given process index to read from and optional buffer size,
|
||||
// read format and IO version
|
||||
UIPstream
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int fromProcNo,
|
||||
DynamicList<char>& externalBuf,
|
||||
const int tag = UPstream::msgType(),
|
||||
streamFormat format=BINARY,
|
||||
versionNumber version=currentVersion
|
||||
);
|
||||
|
||||
//- Construct given buffers
|
||||
UIPstream(const int fromProcNo, PstreamBuffers&);
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
~UIPstream();
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Inquiry
|
||||
|
||||
//- Return flags of output stream
|
||||
ios_base::fmtflags flags() const
|
||||
{
|
||||
return ios_base::fmtflags(0);
|
||||
}
|
||||
|
||||
|
||||
// Read functions
|
||||
|
||||
//- Read into given buffer from given processor and return the
|
||||
// message size
|
||||
static label read
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int fromProcNo,
|
||||
char* buf,
|
||||
const std::streamsize bufSize,
|
||||
const int tag = UPstream::msgType()
|
||||
);
|
||||
|
||||
//- Return next token from stream
|
||||
Istream& read(token&);
|
||||
|
||||
//- Read a character
|
||||
Istream& read(char&);
|
||||
|
||||
//- Read a word
|
||||
Istream& read(word&);
|
||||
|
||||
// Read a string (including enclosing double-quotes)
|
||||
Istream& read(string&);
|
||||
|
||||
//- Read a label
|
||||
Istream& read(label&);
|
||||
|
||||
//- Read a floatScalar
|
||||
Istream& read(floatScalar&);
|
||||
|
||||
//- Read a doubleScalar
|
||||
Istream& read(doubleScalar&);
|
||||
|
||||
//- Read binary block
|
||||
Istream& read(char*, std::streamsize);
|
||||
|
||||
//- Rewind and return the stream so that it may be read again
|
||||
Istream& rewind();
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Set flags of stream
|
||||
ios_base::fmtflags flags(const ios_base::fmtflags)
|
||||
{
|
||||
return ios_base::fmtflags(0);
|
||||
}
|
||||
|
||||
|
||||
// Print
|
||||
|
||||
//- Print description of IOstream to Ostream
|
||||
void print(Ostream&) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
275
src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C
Normal file
275
src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C
Normal file
@ -0,0 +1,275 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
Write primitive and binary block from UOPstream
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
|
||||
#include "UOPstream.H"
|
||||
#include "int.H"
|
||||
#include "token.H"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UOPstream::writeToBuffer(const T& t)
|
||||
{
|
||||
writeToBuffer(&t, sizeof(T), sizeof(T));
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::UOPstream::writeToBuffer(const char& c)
|
||||
{
|
||||
if (!sendBuf_.capacity())
|
||||
{
|
||||
sendBuf_.setCapacity(1000);
|
||||
}
|
||||
sendBuf_.append(c);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::UOPstream::writeToBuffer
|
||||
(
|
||||
const void* data,
|
||||
size_t count,
|
||||
size_t align
|
||||
)
|
||||
{
|
||||
if (!sendBuf_.capacity())
|
||||
{
|
||||
sendBuf_.setCapacity(1000);
|
||||
}
|
||||
|
||||
label alignedPos = sendBuf_.size();
|
||||
|
||||
if (align > 1)
|
||||
{
|
||||
// Align bufPosition. Pads sendBuf_.size() - oldPos characters.
|
||||
alignedPos = align + ((sendBuf_.size() - 1) & ~(align - 1));
|
||||
}
|
||||
|
||||
// Extend if necessary
|
||||
sendBuf_.setSize(alignedPos + count);
|
||||
|
||||
register const char* dataPtr = reinterpret_cast<const char*>(data);
|
||||
register size_t i = count;
|
||||
while (i--) sendBuf_[alignedPos++] = *dataPtr++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::UOPstream::UOPstream
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int toProcNo,
|
||||
DynamicList<char>& sendBuf,
|
||||
const int tag,
|
||||
const bool sendAtDestruct,
|
||||
streamFormat format,
|
||||
versionNumber version
|
||||
)
|
||||
:
|
||||
UPstream(commsType),
|
||||
Ostream(format, version),
|
||||
toProcNo_(toProcNo),
|
||||
sendBuf_(sendBuf),
|
||||
tag_(tag),
|
||||
sendAtDestruct_(sendAtDestruct)
|
||||
{
|
||||
setOpened();
|
||||
setGood();
|
||||
}
|
||||
|
||||
|
||||
Foam::UOPstream::UOPstream(const int toProcNo, PstreamBuffers& buffers)
|
||||
:
|
||||
UPstream(buffers.commsType_),
|
||||
Ostream(buffers.format_, buffers.version_),
|
||||
toProcNo_(toProcNo),
|
||||
sendBuf_(buffers.sendBuf_[toProcNo]),
|
||||
tag_(buffers.tag_),
|
||||
sendAtDestruct_(buffers.commsType_ != UPstream::nonBlocking)
|
||||
{
|
||||
setOpened();
|
||||
setGood();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::UOPstream::~UOPstream()
|
||||
{
|
||||
if (sendAtDestruct_)
|
||||
{
|
||||
if
|
||||
(
|
||||
!UOPstream::write
|
||||
(
|
||||
commsType_,
|
||||
toProcNo_,
|
||||
sendBuf_.begin(),
|
||||
sendBuf_.size(),
|
||||
tag_
|
||||
)
|
||||
)
|
||||
{
|
||||
FatalErrorIn("UOPstream::~UOPstream()")
|
||||
<< "Failed sending outgoing message of size " << sendBuf_.size()
|
||||
<< " to processor " << toProcNo_
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::write(const token&)
|
||||
{
|
||||
notImplemented("Ostream& UOPstream::write(const token&)");
|
||||
setBad();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::write(const char c)
|
||||
{
|
||||
if (!isspace(c))
|
||||
{
|
||||
writeToBuffer(c);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::write(const char* str)
|
||||
{
|
||||
word nonWhiteChars(string::validate<word>(str));
|
||||
|
||||
if (nonWhiteChars.size() == 1)
|
||||
{
|
||||
return write(nonWhiteChars.c_str()[1]);
|
||||
}
|
||||
else if (nonWhiteChars.size())
|
||||
{
|
||||
return write(nonWhiteChars);
|
||||
}
|
||||
else
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::write(const word& str)
|
||||
{
|
||||
write(char(token::WORD));
|
||||
|
||||
size_t len = str.size();
|
||||
writeToBuffer(len);
|
||||
writeToBuffer(str.c_str(), len + 1, 1);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::write(const string& str)
|
||||
{
|
||||
write(char(token::STRING));
|
||||
|
||||
size_t len = str.size();
|
||||
writeToBuffer(len);
|
||||
writeToBuffer(str.c_str(), len + 1, 1);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::writeQuoted(const std::string& str, const bool)
|
||||
{
|
||||
write(char(token::STRING));
|
||||
|
||||
size_t len = str.size();
|
||||
writeToBuffer(len);
|
||||
writeToBuffer(str.c_str(), len + 1, 1);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::write(const label val)
|
||||
{
|
||||
write(char(token::LABEL));
|
||||
writeToBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::write(const floatScalar val)
|
||||
{
|
||||
write(char(token::FLOAT_SCALAR));
|
||||
writeToBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::write(const doubleScalar val)
|
||||
{
|
||||
write(char(token::DOUBLE_SCALAR));
|
||||
writeToBuffer(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::UOPstream::write(const char* data, std::streamsize count)
|
||||
{
|
||||
if (format() != BINARY)
|
||||
{
|
||||
FatalErrorIn("Ostream::write(const char*, std::streamsize)")
|
||||
<< "stream format not binary"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
writeToBuffer(data, count, 8);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Foam::UOPstream::print(Ostream& os) const
|
||||
{
|
||||
os << "Writing from processor " << toProcNo_
|
||||
<< " to processor " << myProcNo() << Foam::endl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
233
src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H
Normal file
233
src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H
Normal file
@ -0,0 +1,233 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::UOPstream
|
||||
|
||||
Description
|
||||
Output inter-processor communications stream operating on external
|
||||
buffer.
|
||||
|
||||
SourceFiles
|
||||
UOPstream.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Pstream.H"
|
||||
|
||||
#ifndef UOPstream_H
|
||||
#define UOPstream_H
|
||||
|
||||
#include "UPstream.H"
|
||||
#include "Ostream.H"
|
||||
#include "DynamicList.H"
|
||||
#include "PstreamBuffers.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class UOPstream Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class UOPstream
|
||||
:
|
||||
public UPstream,
|
||||
public Ostream
|
||||
{
|
||||
// Private data
|
||||
|
||||
int toProcNo_;
|
||||
|
||||
DynamicList<char>& sendBuf_;
|
||||
|
||||
const int tag_;
|
||||
|
||||
const bool sendAtDestruct_;
|
||||
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Write a T to the transfer buffer
|
||||
template<class T>
|
||||
inline void writeToBuffer(const T&);
|
||||
|
||||
//- Write a char to the transfer buffer
|
||||
inline void writeToBuffer(const char&);
|
||||
|
||||
//- Write data to the transfer buffer
|
||||
inline void writeToBuffer(const void* data, size_t count, size_t align);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct given process index to send to and optional buffer size,
|
||||
// write format and IO version
|
||||
UOPstream
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int toProcNo,
|
||||
DynamicList<char>& sendBuf,
|
||||
const int tag = UPstream::msgType(),
|
||||
const bool sendAtDestruct = true,
|
||||
streamFormat format=BINARY,
|
||||
versionNumber version=currentVersion
|
||||
);
|
||||
|
||||
//- Construct given buffers
|
||||
UOPstream(const int toProcNo, PstreamBuffers&);
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
~UOPstream();
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Inquiry
|
||||
|
||||
//- Return flags of output stream
|
||||
ios_base::fmtflags flags() const
|
||||
{
|
||||
return ios_base::fmtflags(0);
|
||||
}
|
||||
|
||||
|
||||
// Write functions
|
||||
|
||||
//- Write given buffer to given processor
|
||||
static bool write
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int toProcNo,
|
||||
const char* buf,
|
||||
const std::streamsize bufSize,
|
||||
const int tag = UPstream::msgType()
|
||||
);
|
||||
|
||||
//- Write next token to stream
|
||||
Ostream& write(const token&);
|
||||
|
||||
//- Write character
|
||||
Ostream& write(const char);
|
||||
|
||||
//- Write character string
|
||||
Ostream& write(const char*);
|
||||
|
||||
//- Write word
|
||||
Ostream& write(const word&);
|
||||
|
||||
//- Write string
|
||||
Ostream& write(const string&);
|
||||
|
||||
//- Write std::string surrounded by quotes.
|
||||
// Optional write without quotes.
|
||||
Ostream& writeQuoted
|
||||
(
|
||||
const std::string&,
|
||||
const bool quoted=true
|
||||
);
|
||||
|
||||
//- Write label
|
||||
Ostream& write(const label);
|
||||
|
||||
//- Write floatScalar
|
||||
Ostream& write(const floatScalar);
|
||||
|
||||
//- Write doubleScalar
|
||||
Ostream& write(const doubleScalar);
|
||||
|
||||
//- Write binary block
|
||||
Ostream& write(const char*, std::streamsize);
|
||||
|
||||
//- Add indentation characters
|
||||
void indent()
|
||||
{}
|
||||
|
||||
|
||||
// Stream state functions
|
||||
|
||||
//- Flush stream
|
||||
void flush()
|
||||
{}
|
||||
|
||||
//- Add newline and flush stream
|
||||
void endl()
|
||||
{}
|
||||
|
||||
//- Get width of output field
|
||||
int width() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- Set width of output field (and return old width)
|
||||
int width(const int)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- Get precision of output field
|
||||
int precision() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- Set precision of output field (and return old precision)
|
||||
int precision(const int)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Set flags of stream
|
||||
ios_base::fmtflags flags(const ios_base::fmtflags)
|
||||
{
|
||||
return ios_base::fmtflags(0);
|
||||
}
|
||||
|
||||
|
||||
// Print
|
||||
|
||||
//- Print description of IOstream to Ostream
|
||||
void print(Ostream&) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
251
src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C
Normal file
251
src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C
Normal file
@ -0,0 +1,251 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "UPstream.H"
|
||||
#include "debug.H"
|
||||
#include "dictionary.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
defineTypeNameAndDebug(Foam::UPstream, 0);
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum<Foam::UPstream::commsTypes, 3>::names[] =
|
||||
{
|
||||
"blocking",
|
||||
"scheduled",
|
||||
"nonBlocking"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum<Foam::UPstream::commsTypes, 3>
|
||||
Foam::UPstream::commsTypeNames;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::UPstream::setParRun()
|
||||
{
|
||||
parRun_ = true;
|
||||
|
||||
Pout.prefix() = '[' + name(myProcNo()) + "] ";
|
||||
Perr.prefix() = '[' + name(myProcNo()) + "] ";
|
||||
}
|
||||
|
||||
|
||||
void Foam::UPstream::calcLinearComm(const label nProcs)
|
||||
{
|
||||
linearCommunication_.setSize(nProcs);
|
||||
|
||||
// Master
|
||||
labelList belowIDs(nProcs - 1);
|
||||
forAll(belowIDs, i)
|
||||
{
|
||||
belowIDs[i] = i + 1;
|
||||
}
|
||||
|
||||
linearCommunication_[0] = commsStruct
|
||||
(
|
||||
nProcs,
|
||||
0,
|
||||
-1,
|
||||
belowIDs,
|
||||
labelList(0)
|
||||
);
|
||||
|
||||
// Slaves. Have no below processors, only communicate up to master
|
||||
for (label procID = 1; procID < nProcs; procID++)
|
||||
{
|
||||
linearCommunication_[procID] = commsStruct
|
||||
(
|
||||
nProcs,
|
||||
procID,
|
||||
0,
|
||||
labelList(0),
|
||||
labelList(0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Append my children (and my children children etc.) to allReceives.
|
||||
void Foam::UPstream::collectReceives
|
||||
(
|
||||
const label procID,
|
||||
const List<DynamicList<label> >& receives,
|
||||
DynamicList<label>& allReceives
|
||||
)
|
||||
{
|
||||
const DynamicList<label>& myChildren = receives[procID];
|
||||
|
||||
forAll(myChildren, childI)
|
||||
{
|
||||
allReceives.append(myChildren[childI]);
|
||||
collectReceives(myChildren[childI], receives, allReceives);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Tree like schedule. For 8 procs:
|
||||
// (level 0)
|
||||
// 0 receives from 1
|
||||
// 2 receives from 3
|
||||
// 4 receives from 5
|
||||
// 6 receives from 7
|
||||
// (level 1)
|
||||
// 0 receives from 2
|
||||
// 4 receives from 6
|
||||
// (level 2)
|
||||
// 0 receives from 4
|
||||
//
|
||||
// The sends/receives for all levels are collected per processor (one send per
|
||||
// processor; multiple receives possible) creating a table:
|
||||
//
|
||||
// So per processor:
|
||||
// proc receives from sends to
|
||||
// ---- ------------- --------
|
||||
// 0 1,2,4 -
|
||||
// 1 - 0
|
||||
// 2 3 0
|
||||
// 3 - 2
|
||||
// 4 5 0
|
||||
// 5 - 4
|
||||
// 6 7 4
|
||||
// 7 - 6
|
||||
void Foam::UPstream::calcTreeComm(label nProcs)
|
||||
{
|
||||
label nLevels = 1;
|
||||
while ((1 << nLevels) < nProcs)
|
||||
{
|
||||
nLevels++;
|
||||
}
|
||||
|
||||
List<DynamicList<label> > receives(nProcs);
|
||||
labelList sends(nProcs, -1);
|
||||
|
||||
// Info<< "Using " << nLevels << " communication levels" << endl;
|
||||
|
||||
label offset = 2;
|
||||
label childOffset = offset/2;
|
||||
|
||||
for (label level = 0; level < nLevels; level++)
|
||||
{
|
||||
label receiveID = 0;
|
||||
while (receiveID < nProcs)
|
||||
{
|
||||
// Determine processor that sends and we receive from
|
||||
label sendID = receiveID + childOffset;
|
||||
|
||||
if (sendID < nProcs)
|
||||
{
|
||||
receives[receiveID].append(sendID);
|
||||
sends[sendID] = receiveID;
|
||||
}
|
||||
|
||||
receiveID += offset;
|
||||
}
|
||||
|
||||
offset <<= 1;
|
||||
childOffset <<= 1;
|
||||
}
|
||||
|
||||
// For all processors find the processors it receives data from
|
||||
// (and the processors they receive data from etc.)
|
||||
List<DynamicList<label> > allReceives(nProcs);
|
||||
for (label procID = 0; procID < nProcs; procID++)
|
||||
{
|
||||
collectReceives(procID, receives, allReceives[procID]);
|
||||
}
|
||||
|
||||
|
||||
treeCommunication_.setSize(nProcs);
|
||||
|
||||
for (label procID = 0; procID < nProcs; procID++)
|
||||
{
|
||||
treeCommunication_[procID] = commsStruct
|
||||
(
|
||||
nProcs,
|
||||
procID,
|
||||
sends[procID],
|
||||
receives[procID].shrink(),
|
||||
allReceives[procID].shrink()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Callback from UPstream::init() : initialize linear and tree communication
|
||||
// schedules now that nProcs is known.
|
||||
void Foam::UPstream::initCommunicationSchedule()
|
||||
{
|
||||
calcLinearComm(nProcs());
|
||||
calcTreeComm(nProcs());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// Initialise my process number to 0 (the master)
|
||||
int Foam::UPstream::myProcNo_(0);
|
||||
|
||||
// By default this is not a parallel run
|
||||
bool Foam::UPstream::parRun_(false);
|
||||
|
||||
// List of process IDs
|
||||
Foam::List<int> Foam::UPstream::procIDs_(1, 0);
|
||||
|
||||
// Standard transfer message type
|
||||
int Foam::UPstream::msgType_(1);
|
||||
|
||||
// Linear communication schedule
|
||||
Foam::List<Foam::UPstream::commsStruct> Foam::UPstream::linearCommunication_(0);
|
||||
|
||||
// Multi level communication schedule
|
||||
Foam::List<Foam::UPstream::commsStruct> Foam::UPstream::treeCommunication_(0);
|
||||
|
||||
// Should compact transfer be used in which floats replace doubles
|
||||
// reducing the bandwidth requirement at the expense of some loss
|
||||
// in accuracy
|
||||
bool Foam::UPstream::floatTransfer
|
||||
(
|
||||
debug::optimisationSwitch("floatTransfer", 0)
|
||||
);
|
||||
|
||||
// Number of processors at which the reduce algorithm changes from linear to
|
||||
// tree
|
||||
int Foam::UPstream::nProcsSimpleSum
|
||||
(
|
||||
debug::optimisationSwitch("nProcsSimpleSum", 16)
|
||||
);
|
||||
|
||||
// Default commsType
|
||||
Foam::UPstream::commsTypes Foam::UPstream::defaultCommsType
|
||||
(
|
||||
commsTypeNames.read(debug::optimisationSwitches().lookup("commsType"))
|
||||
);
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
381
src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H
Normal file
381
src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H
Normal file
@ -0,0 +1,381 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::UPstream
|
||||
|
||||
Description
|
||||
Inter-processor communications stream
|
||||
|
||||
SourceFiles
|
||||
UPstream.C
|
||||
UPstreamsPrint.C
|
||||
UPstreamCommsStruct.C
|
||||
gatherScatter.C
|
||||
combineGatherScatter.C
|
||||
gatherScatterList.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef UPstream_H
|
||||
#define UPstream_H
|
||||
|
||||
#include "labelList.H"
|
||||
#include "DynamicList.H"
|
||||
#include "HashTable.H"
|
||||
#include "string.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class UPstream Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class UPstream
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Types of communications
|
||||
enum commsTypes
|
||||
{
|
||||
blocking,
|
||||
scheduled,
|
||||
nonBlocking
|
||||
};
|
||||
|
||||
static const NamedEnum<commsTypes, 3> commsTypeNames;
|
||||
|
||||
// Public classes
|
||||
|
||||
//- Structure for communicating between processors
|
||||
class commsStruct
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- procID of above processor
|
||||
label above_;
|
||||
|
||||
//- procIDs of processors directly below me
|
||||
labelList below_;
|
||||
|
||||
//- procIDs of all processors below (so not just directly below)
|
||||
labelList allBelow_;
|
||||
|
||||
//- procIDs of all processors not below. (inverse set of
|
||||
// allBelow_ and minus myProcNo)
|
||||
labelList allNotBelow_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
commsStruct();
|
||||
|
||||
//- Construct from components
|
||||
commsStruct
|
||||
(
|
||||
const label,
|
||||
const labelList&,
|
||||
const labelList&,
|
||||
const labelList&
|
||||
);
|
||||
|
||||
//- Construct from components; construct allNotBelow_
|
||||
commsStruct
|
||||
(
|
||||
const label nProcs,
|
||||
const label myProcID,
|
||||
const label,
|
||||
const labelList&,
|
||||
const labelList&
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
label above() const
|
||||
{
|
||||
return above_;
|
||||
}
|
||||
|
||||
const labelList& below() const
|
||||
{
|
||||
return below_;
|
||||
}
|
||||
|
||||
const labelList& allBelow() const
|
||||
{
|
||||
return allBelow_;
|
||||
}
|
||||
|
||||
const labelList& allNotBelow() const
|
||||
{
|
||||
return allNotBelow_;
|
||||
}
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
bool operator==(const commsStruct&) const;
|
||||
|
||||
bool operator!=(const commsStruct&) const;
|
||||
|
||||
|
||||
// Ostream Operator
|
||||
|
||||
friend Ostream& operator<<(Ostream&, const commsStruct&);
|
||||
};
|
||||
|
||||
|
||||
//- combineReduce operator for lists. Used for counting.
|
||||
class listEq
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
template<class T>
|
||||
void operator()(T& x, const T& y) const
|
||||
{
|
||||
forAll(y, i)
|
||||
{
|
||||
if (y[i].size())
|
||||
{
|
||||
x[i] = y[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
static int myProcNo_;
|
||||
static bool parRun_;
|
||||
|
||||
static List<int> procIDs_;
|
||||
static int msgType_;
|
||||
|
||||
static List<commsStruct> linearCommunication_;
|
||||
static List<commsStruct> treeCommunication_;
|
||||
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Set data for parallel running
|
||||
static void setParRun();
|
||||
|
||||
//- Calculate linear communication schedule
|
||||
static void calcLinearComm(const label nProcs);
|
||||
|
||||
//- Calculate tree communication schedule
|
||||
static void calcTreeComm(const label nProcs);
|
||||
|
||||
//- Helper function for tree communication schedule determination
|
||||
// Collects all processorIDs below a processor
|
||||
static void collectReceives
|
||||
(
|
||||
const label procID,
|
||||
const List<DynamicList<label> >& receives,
|
||||
DynamicList<label>& allReceives
|
||||
);
|
||||
|
||||
//- Initialize all communication schedules. Callback from
|
||||
// UPstream::init()
|
||||
static void initCommunicationSchedule();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Communications type of this stream
|
||||
commsTypes commsType_;
|
||||
|
||||
public:
|
||||
|
||||
// Declare name of the class and its debug switch
|
||||
ClassName("UPstream");
|
||||
|
||||
|
||||
// Static data
|
||||
|
||||
//- Should compact transfer be used in which floats replace doubles
|
||||
// reducing the bandwidth requirement at the expense of some loss
|
||||
// in accuracy
|
||||
static bool floatTransfer;
|
||||
|
||||
//- Number of processors at which the sum algorithm changes from linear
|
||||
// to tree
|
||||
static int nProcsSimpleSum;
|
||||
|
||||
//- Default commsType
|
||||
static commsTypes defaultCommsType;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct given optional buffer size
|
||||
UPstream(const commsTypes commsType)
|
||||
:
|
||||
commsType_(commsType)
|
||||
{}
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Add the valid option this type of communications library
|
||||
// adds/requires on the command line
|
||||
static void addValidParOptions(HashTable<string>& validParOptions);
|
||||
|
||||
//- Initialisation function called from main
|
||||
// Spawns slave processes and initialises inter-communication
|
||||
static bool init(int& argc, char**& argv);
|
||||
|
||||
//- Non-blocking comms: wait until all have finished.
|
||||
static void waitRequests();
|
||||
|
||||
//- Non-blocking comms: has request i finished?
|
||||
static bool finishedRequest(const label i);
|
||||
|
||||
//- Is this a parallel run?
|
||||
static bool parRun()
|
||||
{
|
||||
return parRun_;
|
||||
}
|
||||
|
||||
//- Number of processes in parallel run
|
||||
static label nProcs()
|
||||
{
|
||||
return procIDs_.size();
|
||||
}
|
||||
|
||||
//- Am I the master process
|
||||
static bool master()
|
||||
{
|
||||
return myProcNo_ == 0;
|
||||
}
|
||||
|
||||
//- Process index of the master
|
||||
static int masterNo()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- Number of this process (starting from masterNo() = 0)
|
||||
static int myProcNo()
|
||||
{
|
||||
return myProcNo_;
|
||||
}
|
||||
|
||||
//- Process IDs
|
||||
static const List<int>& procIDs()
|
||||
{
|
||||
return procIDs_;
|
||||
}
|
||||
|
||||
//- Process ID of given process index
|
||||
static int procID(int procNo)
|
||||
{
|
||||
return procIDs_[procNo];
|
||||
}
|
||||
|
||||
//- Process index of first slave
|
||||
static int firstSlave()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
//- Process index of last slave
|
||||
static int lastSlave()
|
||||
{
|
||||
return nProcs() - 1;
|
||||
}
|
||||
|
||||
//- Communication schedule for linear all-to-master (proc 0)
|
||||
static const List<commsStruct>& linearCommunication()
|
||||
{
|
||||
return linearCommunication_;
|
||||
}
|
||||
|
||||
//- Communication schedule for tree all-to-master (proc 0)
|
||||
static const List<commsStruct>& treeCommunication()
|
||||
{
|
||||
return treeCommunication_;
|
||||
}
|
||||
|
||||
//- Message tag of standard messages
|
||||
static int& msgType()
|
||||
{
|
||||
return msgType_;
|
||||
}
|
||||
|
||||
|
||||
//- Get the communications type of the stream
|
||||
commsTypes commsType() const
|
||||
{
|
||||
return commsType_;
|
||||
}
|
||||
|
||||
//- Set the communications type of the stream
|
||||
commsTypes commsType(const commsTypes ct)
|
||||
{
|
||||
commsTypes oldCommsType = commsType_;
|
||||
commsType_ = ct;
|
||||
return oldCommsType;
|
||||
}
|
||||
|
||||
|
||||
//- Exit program
|
||||
static void exit(int errnum = 1);
|
||||
|
||||
//- Abort program
|
||||
static void abort();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
Ostream& operator<<(Ostream&, const UPstream::commsStruct&);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,12 +24,12 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Pstream.H"
|
||||
#include "UPstream.H"
|
||||
#include "boolList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Pstream::commsStruct::commsStruct()
|
||||
Foam::UPstream::commsStruct::commsStruct()
|
||||
:
|
||||
above_(-1),
|
||||
below_(0),
|
||||
@ -38,7 +38,7 @@ Foam::Pstream::commsStruct::commsStruct()
|
||||
{}
|
||||
|
||||
|
||||
Foam::Pstream::commsStruct::commsStruct
|
||||
Foam::UPstream::commsStruct::commsStruct
|
||||
(
|
||||
const label above,
|
||||
const labelList& below,
|
||||
@ -53,7 +53,7 @@ Foam::Pstream::commsStruct::commsStruct
|
||||
{}
|
||||
|
||||
|
||||
Foam::Pstream::commsStruct::commsStruct
|
||||
Foam::UPstream::commsStruct::commsStruct
|
||||
(
|
||||
const label nProcs,
|
||||
const label myProcID,
|
||||
@ -91,7 +91,7 @@ Foam::Pstream::commsStruct::commsStruct
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::Pstream::commsStruct::operator==(const commsStruct& comm) const
|
||||
bool Foam::UPstream::commsStruct::operator==(const commsStruct& comm) const
|
||||
{
|
||||
return
|
||||
(
|
||||
@ -103,7 +103,7 @@ bool Foam::Pstream::commsStruct::operator==(const commsStruct& comm) const
|
||||
}
|
||||
|
||||
|
||||
bool Foam::Pstream::commsStruct::operator!=(const commsStruct& comm) const
|
||||
bool Foam::UPstream::commsStruct::operator!=(const commsStruct& comm) const
|
||||
{
|
||||
return !operator==(comm);
|
||||
}
|
||||
@ -111,7 +111,7 @@ bool Foam::Pstream::commsStruct::operator!=(const commsStruct& comm) const
|
||||
|
||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const Pstream::commsStruct& comm)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const UPstream::commsStruct& comm)
|
||||
{
|
||||
os << comm.above_ << token::SPACE
|
||||
<< comm.below_ << token::SPACE
|
||||
@ -49,15 +49,15 @@ namespace Foam
|
||||
template <class T, class CombineOp>
|
||||
void Pstream::combineGather
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
T& Value,
|
||||
const CombineOp& cop
|
||||
)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
// Get my communication order
|
||||
const commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Receive from my downstairs neighbours
|
||||
forAll(myComm.below(), belowI)
|
||||
@ -67,9 +67,9 @@ void Pstream::combineGather
|
||||
if (contiguous<T>())
|
||||
{
|
||||
T value;
|
||||
IPstream::read
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
belowID,
|
||||
reinterpret_cast<char*>(&value),
|
||||
sizeof(T)
|
||||
@ -85,7 +85,7 @@ void Pstream::combineGather
|
||||
}
|
||||
else
|
||||
{
|
||||
IPstream fromBelow(Pstream::scheduled, belowID);
|
||||
IPstream fromBelow(UPstream::scheduled, belowID);
|
||||
T value(fromBelow);
|
||||
|
||||
if (debug & 2)
|
||||
@ -109,9 +109,9 @@ void Pstream::combineGather
|
||||
|
||||
if (contiguous<T>())
|
||||
{
|
||||
OPstream::write
|
||||
UOPstream::write
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.above(),
|
||||
reinterpret_cast<const char*>(&Value),
|
||||
sizeof(T)
|
||||
@ -119,7 +119,7 @@ void Pstream::combineGather
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toAbove(Pstream::scheduled, myComm.above());
|
||||
OPstream toAbove(UPstream::scheduled, myComm.above());
|
||||
toAbove << Value;
|
||||
}
|
||||
}
|
||||
@ -130,33 +130,37 @@ void Pstream::combineGather
|
||||
template <class T, class CombineOp>
|
||||
void Pstream::combineGather(T& Value, const CombineOp& cop)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
combineGather(Pstream::linearCommunication(), Value, cop);
|
||||
combineGather(UPstream::linearCommunication(), Value, cop);
|
||||
}
|
||||
else
|
||||
{
|
||||
combineGather(Pstream::treeCommunication(), Value, cop);
|
||||
combineGather(UPstream::treeCommunication(), Value, cop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
void Pstream::combineScatter
|
||||
(
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
T& Value
|
||||
)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
// Get my communication order
|
||||
const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const UPstream::commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Reveive from up
|
||||
if (myComm.above() != -1)
|
||||
{
|
||||
if (contiguous<T>())
|
||||
{
|
||||
IPstream::read
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.above(),
|
||||
reinterpret_cast<char*>(&Value),
|
||||
sizeof(T)
|
||||
@ -164,7 +168,7 @@ void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
}
|
||||
else
|
||||
{
|
||||
IPstream fromAbove(Pstream::scheduled, myComm.above());
|
||||
IPstream fromAbove(UPstream::scheduled, myComm.above());
|
||||
Value = T(fromAbove);
|
||||
}
|
||||
|
||||
@ -187,9 +191,9 @@ void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
|
||||
if (contiguous<T>())
|
||||
{
|
||||
OPstream::write
|
||||
UOPstream::write
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
belowID,
|
||||
reinterpret_cast<const char*>(&Value),
|
||||
sizeof(T)
|
||||
@ -197,7 +201,7 @@ void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toBelow(Pstream::scheduled, belowID);
|
||||
OPstream toBelow(UPstream::scheduled, belowID);
|
||||
toBelow << Value;
|
||||
}
|
||||
}
|
||||
@ -208,13 +212,13 @@ void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
template <class T>
|
||||
void Pstream::combineScatter(T& Value)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
combineScatter(Pstream::linearCommunication(), Value);
|
||||
combineScatter(UPstream::linearCommunication(), Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
combineScatter(Pstream::treeCommunication(), Value);
|
||||
combineScatter(UPstream::treeCommunication(), Value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,15 +230,15 @@ void Pstream::combineScatter(T& Value)
|
||||
template <class T, class CombineOp>
|
||||
void Pstream::listCombineGather
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
List<T>& Values,
|
||||
const CombineOp& cop
|
||||
)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
// Get my communication order
|
||||
const commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Receive from my downstairs neighbours
|
||||
forAll(myComm.below(), belowI)
|
||||
@ -245,9 +249,9 @@ void Pstream::listCombineGather
|
||||
{
|
||||
List<T> receivedValues(Values.size());
|
||||
|
||||
IPstream::read
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
belowID,
|
||||
reinterpret_cast<char*>(receivedValues.begin()),
|
||||
receivedValues.byteSize()
|
||||
@ -266,7 +270,7 @@ void Pstream::listCombineGather
|
||||
}
|
||||
else
|
||||
{
|
||||
IPstream fromBelow(Pstream::scheduled, belowID);
|
||||
IPstream fromBelow(UPstream::scheduled, belowID);
|
||||
List<T> receivedValues(fromBelow);
|
||||
|
||||
if (debug & 2)
|
||||
@ -293,9 +297,9 @@ void Pstream::listCombineGather
|
||||
|
||||
if (contiguous<T>())
|
||||
{
|
||||
OPstream::write
|
||||
UOPstream::write
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.above(),
|
||||
reinterpret_cast<const char*>(Values.begin()),
|
||||
Values.byteSize()
|
||||
@ -303,7 +307,7 @@ void Pstream::listCombineGather
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toAbove(Pstream::scheduled, myComm.above());
|
||||
OPstream toAbove(UPstream::scheduled, myComm.above());
|
||||
toAbove << Values;
|
||||
}
|
||||
}
|
||||
@ -314,13 +318,13 @@ void Pstream::listCombineGather
|
||||
template <class T, class CombineOp>
|
||||
void Pstream::listCombineGather(List<T>& Values, const CombineOp& cop)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
listCombineGather(Pstream::linearCommunication(), Values, cop);
|
||||
listCombineGather(UPstream::linearCommunication(), Values, cop);
|
||||
}
|
||||
else
|
||||
{
|
||||
listCombineGather(Pstream::treeCommunication(), Values, cop);
|
||||
listCombineGather(UPstream::treeCommunication(), Values, cop);
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,23 +332,23 @@ void Pstream::listCombineGather(List<T>& Values, const CombineOp& cop)
|
||||
template <class T>
|
||||
void Pstream::listCombineScatter
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
List<T>& Values
|
||||
)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
// Get my communication order
|
||||
const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const UPstream::commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Reveive from up
|
||||
if (myComm.above() != -1)
|
||||
{
|
||||
if (contiguous<T>())
|
||||
{
|
||||
IPstream::read
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.above(),
|
||||
reinterpret_cast<char*>(Values.begin()),
|
||||
Values.byteSize()
|
||||
@ -352,7 +356,7 @@ void Pstream::listCombineScatter
|
||||
}
|
||||
else
|
||||
{
|
||||
IPstream fromAbove(Pstream::scheduled, myComm.above());
|
||||
IPstream fromAbove(UPstream::scheduled, myComm.above());
|
||||
fromAbove >> Values;
|
||||
}
|
||||
|
||||
@ -375,9 +379,9 @@ void Pstream::listCombineScatter
|
||||
|
||||
if (contiguous<T>())
|
||||
{
|
||||
OPstream::write
|
||||
UOPstream::write
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
belowID,
|
||||
reinterpret_cast<const char*>(Values.begin()),
|
||||
Values.byteSize()
|
||||
@ -385,7 +389,7 @@ void Pstream::listCombineScatter
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toBelow(Pstream::scheduled, belowID);
|
||||
OPstream toBelow(UPstream::scheduled, belowID);
|
||||
toBelow << Values;
|
||||
}
|
||||
}
|
||||
@ -396,13 +400,13 @@ void Pstream::listCombineScatter
|
||||
template <class T>
|
||||
void Pstream::listCombineScatter(List<T>& Values)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
listCombineScatter(Pstream::linearCommunication(), Values);
|
||||
listCombineScatter(UPstream::linearCommunication(), Values);
|
||||
}
|
||||
else
|
||||
{
|
||||
listCombineScatter(Pstream::treeCommunication(), Values);
|
||||
listCombineScatter(UPstream::treeCommunication(), Values);
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,22 +420,22 @@ void Pstream::listCombineScatter(List<T>& Values)
|
||||
template <class Container, class CombineOp>
|
||||
void Pstream::mapCombineGather
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
Container& Values,
|
||||
const CombineOp& cop
|
||||
)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
// Get my communication order
|
||||
const commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Receive from my downstairs neighbours
|
||||
forAll(myComm.below(), belowI)
|
||||
{
|
||||
label belowID = myComm.below()[belowI];
|
||||
|
||||
IPstream fromBelow(Pstream::scheduled, belowID);
|
||||
IPstream fromBelow(UPstream::scheduled, belowID);
|
||||
Container receivedValues(fromBelow);
|
||||
|
||||
if (debug & 2)
|
||||
@ -471,7 +475,7 @@ void Pstream::mapCombineGather
|
||||
<< " data:" << Values << endl;
|
||||
}
|
||||
|
||||
OPstream toAbove(Pstream::scheduled, myComm.above());
|
||||
OPstream toAbove(UPstream::scheduled, myComm.above());
|
||||
toAbove << Values;
|
||||
}
|
||||
}
|
||||
@ -481,13 +485,13 @@ void Pstream::mapCombineGather
|
||||
template <class Container, class CombineOp>
|
||||
void Pstream::mapCombineGather(Container& Values, const CombineOp& cop)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
mapCombineGather(Pstream::linearCommunication(), Values, cop);
|
||||
mapCombineGather(UPstream::linearCommunication(), Values, cop);
|
||||
}
|
||||
else
|
||||
{
|
||||
mapCombineGather(Pstream::treeCommunication(), Values, cop);
|
||||
mapCombineGather(UPstream::treeCommunication(), Values, cop);
|
||||
}
|
||||
}
|
||||
|
||||
@ -495,19 +499,19 @@ void Pstream::mapCombineGather(Container& Values, const CombineOp& cop)
|
||||
template <class Container>
|
||||
void Pstream::mapCombineScatter
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
Container& Values
|
||||
)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
// Get my communication order
|
||||
const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const UPstream::commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Reveive from up
|
||||
if (myComm.above() != -1)
|
||||
{
|
||||
IPstream fromAbove(Pstream::scheduled, myComm.above());
|
||||
IPstream fromAbove(UPstream::scheduled, myComm.above());
|
||||
fromAbove >> Values;
|
||||
|
||||
if (debug & 2)
|
||||
@ -527,7 +531,7 @@ void Pstream::mapCombineScatter
|
||||
Pout<< " sending to " << belowID << " data:" << Values << endl;
|
||||
}
|
||||
|
||||
OPstream toBelow(Pstream::scheduled, belowID);
|
||||
OPstream toBelow(UPstream::scheduled, belowID);
|
||||
toBelow << Values;
|
||||
}
|
||||
}
|
||||
@ -537,19 +541,17 @@ void Pstream::mapCombineScatter
|
||||
template <class Container>
|
||||
void Pstream::mapCombineScatter(Container& Values)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
mapCombineScatter(Pstream::linearCommunication(), Values);
|
||||
mapCombineScatter(UPstream::linearCommunication(), Values);
|
||||
}
|
||||
else
|
||||
{
|
||||
mapCombineScatter(Pstream::treeCommunication(), Values);
|
||||
mapCombineScatter(UPstream::treeCommunication(), Values);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
160
src/OpenFOAM/db/IOstreams/Pstreams/exchange.C
Normal file
160
src/OpenFOAM/db/IOstreams/Pstreams/exchange.C
Normal file
@ -0,0 +1,160 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
Exchange data.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Pstream.H"
|
||||
#include "contiguous.H"
|
||||
#include "PstreamCombineReduceOps.H"
|
||||
#include "UPstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
//template <template<class> class ListType, class T>
|
||||
template <class Container, class T>
|
||||
void Pstream::exchange
|
||||
(
|
||||
const List<Container >& sendBufs,
|
||||
List<Container >& recvBufs,
|
||||
labelListList& sizes,
|
||||
const int tag,
|
||||
const bool block
|
||||
)
|
||||
{
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
if (!contiguous<T>())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Pstream::exchange(..)"
|
||||
) << "Continuous data only." << Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
if (sendBufs.size() != UPstream::nProcs())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Pstream::exchange(..)"
|
||||
) << "Size of list:" << sendBufs.size()
|
||||
<< " does not equal the number of processors:"
|
||||
<< UPstream::nProcs()
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
sizes.setSize(UPstream::nProcs());
|
||||
labelList& nsTransPs = sizes[UPstream::myProcNo()];
|
||||
nsTransPs.setSize(UPstream::nProcs());
|
||||
|
||||
forAll(sendBufs, procI)
|
||||
{
|
||||
nsTransPs[procI] = sendBufs[procI].size();
|
||||
}
|
||||
|
||||
// Send sizes across.
|
||||
int oldTag = UPstream::msgType();
|
||||
UPstream::msgType() = tag;
|
||||
combineReduce(sizes, UPstream::listEq());
|
||||
UPstream::msgType() = oldTag;
|
||||
|
||||
|
||||
// Set up receives
|
||||
// ~~~~~~~~~~~~~~~
|
||||
|
||||
recvBufs.setSize(sendBufs.size());
|
||||
forAll(sizes, procI)
|
||||
{
|
||||
label nRecv = sizes[procI][UPstream::myProcNo()];
|
||||
|
||||
if (procI != Pstream::myProcNo() && nRecv > 0)
|
||||
{
|
||||
recvBufs[procI].setSize(nRecv);
|
||||
UIPstream::read
|
||||
(
|
||||
UPstream::nonBlocking,
|
||||
procI,
|
||||
reinterpret_cast<char*>(recvBufs[procI].begin()),
|
||||
nRecv*sizeof(T),
|
||||
tag
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set up sends
|
||||
// ~~~~~~~~~~~~
|
||||
|
||||
forAll(sendBufs, procI)
|
||||
{
|
||||
if (procI != Pstream::myProcNo() && sendBufs[procI].size() > 0)
|
||||
{
|
||||
if
|
||||
(
|
||||
!UOPstream::write
|
||||
(
|
||||
UPstream::nonBlocking,
|
||||
procI,
|
||||
reinterpret_cast<const char*>(sendBufs[procI].begin()),
|
||||
sendBufs[procI].size()*sizeof(T),
|
||||
tag
|
||||
)
|
||||
)
|
||||
{
|
||||
FatalErrorIn("Pstream::exchange(..)")
|
||||
<< "Cannot send outgoing message. "
|
||||
<< "to:" << procI << " nBytes:"
|
||||
<< label(sendBufs[procI].size()*sizeof(T))
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Wait for all to finish
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
if (block)
|
||||
{
|
||||
Pstream::waitRequests();
|
||||
}
|
||||
}
|
||||
|
||||
// Do myself
|
||||
recvBufs[Pstream::myProcNo()] = sendBufs[Pstream::myProcNo()];
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -30,7 +30,9 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "UOPstream.H"
|
||||
#include "OPstream.H"
|
||||
#include "UIPstream.H"
|
||||
#include "IPstream.H"
|
||||
#include "contiguous.H"
|
||||
|
||||
@ -44,15 +46,15 @@ namespace Foam
|
||||
template <class T, class BinaryOp>
|
||||
void Pstream::gather
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
T& Value,
|
||||
const BinaryOp& bop
|
||||
)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
// Get my communication order
|
||||
const commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Receive from my downstairs neighbours
|
||||
forAll(myComm.below(), belowI)
|
||||
@ -61,9 +63,9 @@ void Pstream::gather
|
||||
|
||||
if (contiguous<T>())
|
||||
{
|
||||
IPstream::read
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.below()[belowI],
|
||||
reinterpret_cast<char*>(&value),
|
||||
sizeof(T)
|
||||
@ -71,7 +73,7 @@ void Pstream::gather
|
||||
}
|
||||
else
|
||||
{
|
||||
IPstream fromBelow(Pstream::scheduled, myComm.below()[belowI]);
|
||||
IPstream fromBelow(UPstream::scheduled, myComm.below()[belowI]);
|
||||
fromBelow >> value;
|
||||
}
|
||||
|
||||
@ -83,9 +85,9 @@ void Pstream::gather
|
||||
{
|
||||
if (contiguous<T>())
|
||||
{
|
||||
OPstream::write
|
||||
UOPstream::write
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.above(),
|
||||
reinterpret_cast<const char*>(&Value),
|
||||
sizeof(T)
|
||||
@ -93,7 +95,7 @@ void Pstream::gather
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toAbove(Pstream::scheduled, myComm.above());
|
||||
OPstream toAbove(UPstream::scheduled, myComm.above());
|
||||
toAbove << Value;
|
||||
}
|
||||
}
|
||||
@ -104,33 +106,33 @@ void Pstream::gather
|
||||
template <class T, class BinaryOp>
|
||||
void Pstream::gather(T& Value, const BinaryOp& bop)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
gather(Pstream::linearCommunication(), Value, bop);
|
||||
gather(UPstream::linearCommunication(), Value, bop);
|
||||
}
|
||||
else
|
||||
{
|
||||
gather(Pstream::treeCommunication(), Value, bop);
|
||||
gather(UPstream::treeCommunication(), Value, bop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
void Pstream::scatter(const List<UPstream::commsStruct>& comms, T& Value)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
// Get my communication order
|
||||
const commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Reveive from up
|
||||
if (myComm.above() != -1)
|
||||
{
|
||||
if (contiguous<T>())
|
||||
{
|
||||
IPstream::read
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.above(),
|
||||
reinterpret_cast<char*>(&Value),
|
||||
sizeof(T)
|
||||
@ -138,7 +140,7 @@ void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
}
|
||||
else
|
||||
{
|
||||
IPstream fromAbove(Pstream::scheduled, myComm.above());
|
||||
IPstream fromAbove(UPstream::scheduled, myComm.above());
|
||||
fromAbove >> Value;
|
||||
}
|
||||
}
|
||||
@ -148,9 +150,9 @@ void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
{
|
||||
if (contiguous<T>())
|
||||
{
|
||||
OPstream::write
|
||||
UOPstream::write
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.below()[belowI],
|
||||
reinterpret_cast<const char*>(&Value),
|
||||
sizeof(T)
|
||||
@ -158,7 +160,7 @@ void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toBelow(Pstream::scheduled,myComm.below()[belowI]);
|
||||
OPstream toBelow(UPstream::scheduled,myComm.below()[belowI]);
|
||||
toBelow << Value;
|
||||
}
|
||||
}
|
||||
@ -169,13 +171,13 @@ void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
|
||||
template <class T>
|
||||
void Pstream::scatter(T& Value)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
scatter(Pstream::linearCommunication(), Value);
|
||||
scatter(UPstream::linearCommunication(), Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
scatter(Pstream::treeCommunication(), Value);
|
||||
scatter(UPstream::treeCommunication(), Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ Description
|
||||
communication schedule (usually linear-to-master or tree-to-master).
|
||||
The gathered data will be a list with element procID the data from processor
|
||||
procID. Before calling every processor should insert its value into
|
||||
Values[Pstream::myProcNo()].
|
||||
Values[UPstream::myProcNo()].
|
||||
Note: after gather every processor only knows its own data and that of the
|
||||
processors below it. Only the 'master' of the communication schedule holds
|
||||
a fully filled List. Use scatter to distribute the data.
|
||||
@ -48,26 +48,26 @@ namespace Foam
|
||||
template <class T>
|
||||
void Pstream::gatherList
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
List<T>& Values
|
||||
)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
if (Values.size() != Pstream::nProcs())
|
||||
if (Values.size() != UPstream::nProcs())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Pstream::gatherList(const List<Pstream::commsStruct>&"
|
||||
"UPstream::gatherList(const List<UPstream::commsStruct>&"
|
||||
", List<T>)"
|
||||
) << "Size of list:" << Values.size()
|
||||
<< " does not equal the number of processors:"
|
||||
<< Pstream::nProcs()
|
||||
<< UPstream::nProcs()
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
// Get my communication order
|
||||
const commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Receive from my downstairs neighbours
|
||||
forAll(myComm.below(), belowI)
|
||||
@ -79,9 +79,9 @@ void Pstream::gatherList
|
||||
{
|
||||
List<T> receivedValues(belowLeaves.size() + 1);
|
||||
|
||||
IPstream::read
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
belowID,
|
||||
reinterpret_cast<char*>(receivedValues.begin()),
|
||||
receivedValues.byteSize()
|
||||
@ -96,7 +96,7 @@ void Pstream::gatherList
|
||||
}
|
||||
else
|
||||
{
|
||||
IPstream fromBelow(Pstream::scheduled, belowID);
|
||||
IPstream fromBelow(UPstream::scheduled, belowID);
|
||||
fromBelow >> Values[belowID];
|
||||
|
||||
if (debug & 2)
|
||||
@ -132,14 +132,14 @@ void Pstream::gatherList
|
||||
if (debug & 2)
|
||||
{
|
||||
Pout<< " sending to " << myComm.above()
|
||||
<< " data from me:" << Pstream::myProcNo()
|
||||
<< " data:" << Values[Pstream::myProcNo()] << endl;
|
||||
<< " data from me:" << UPstream::myProcNo()
|
||||
<< " data:" << Values[UPstream::myProcNo()] << endl;
|
||||
}
|
||||
|
||||
if (contiguous<T>())
|
||||
{
|
||||
List<T> sendingValues(belowLeaves.size() + 1);
|
||||
sendingValues[0] = Values[Pstream::myProcNo()];
|
||||
sendingValues[0] = Values[UPstream::myProcNo()];
|
||||
|
||||
forAll(belowLeaves, leafI)
|
||||
{
|
||||
@ -148,7 +148,7 @@ void Pstream::gatherList
|
||||
|
||||
OPstream::write
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.above(),
|
||||
reinterpret_cast<const char*>(sendingValues.begin()),
|
||||
sendingValues.byteSize()
|
||||
@ -156,8 +156,8 @@ void Pstream::gatherList
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toAbove(Pstream::scheduled, myComm.above());
|
||||
toAbove << Values[Pstream::myProcNo()];
|
||||
OPstream toAbove(UPstream::scheduled, myComm.above());
|
||||
toAbove << Values[UPstream::myProcNo()];
|
||||
|
||||
forAll(belowLeaves, leafI)
|
||||
{
|
||||
@ -180,13 +180,13 @@ void Pstream::gatherList
|
||||
template <class T>
|
||||
void Pstream::gatherList(List<T>& Values)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
gatherList(Pstream::linearCommunication(), Values);
|
||||
gatherList(UPstream::linearCommunication(), Values);
|
||||
}
|
||||
else
|
||||
{
|
||||
gatherList(Pstream::treeCommunication(), Values);
|
||||
gatherList(UPstream::treeCommunication(), Values);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,26 +194,26 @@ void Pstream::gatherList(List<T>& Values)
|
||||
template <class T>
|
||||
void Pstream::scatterList
|
||||
(
|
||||
const List<Pstream::commsStruct>& comms,
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
List<T>& Values
|
||||
)
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
if (Values.size() != Pstream::nProcs())
|
||||
if (Values.size() != UPstream::nProcs())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Pstream::scatterList(const List<Pstream::commsStruct>&"
|
||||
"UPstream::scatterList(const List<UPstream::commsStruct>&"
|
||||
", List<T>)"
|
||||
) << "Size of list:" << Values.size()
|
||||
<< " does not equal the number of processors:"
|
||||
<< Pstream::nProcs()
|
||||
<< UPstream::nProcs()
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
// Get my communication order
|
||||
const commsStruct& myComm = comms[Pstream::myProcNo()];
|
||||
const commsStruct& myComm = comms[UPstream::myProcNo()];
|
||||
|
||||
// Reveive from up
|
||||
if (myComm.above() != -1)
|
||||
@ -224,9 +224,9 @@ void Pstream::scatterList
|
||||
{
|
||||
List<T> receivedValues(notBelowLeaves.size());
|
||||
|
||||
IPstream::read
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
myComm.above(),
|
||||
reinterpret_cast<char*>(receivedValues.begin()),
|
||||
receivedValues.byteSize()
|
||||
@ -239,7 +239,7 @@ void Pstream::scatterList
|
||||
}
|
||||
else
|
||||
{
|
||||
IPstream fromAbove(Pstream::scheduled, myComm.above());
|
||||
IPstream fromAbove(UPstream::scheduled, myComm.above());
|
||||
|
||||
forAll(notBelowLeaves, leafI)
|
||||
{
|
||||
@ -273,7 +273,7 @@ void Pstream::scatterList
|
||||
|
||||
OPstream::write
|
||||
(
|
||||
Pstream::scheduled,
|
||||
UPstream::scheduled,
|
||||
belowID,
|
||||
reinterpret_cast<const char*>(sendingValues.begin()),
|
||||
sendingValues.byteSize()
|
||||
@ -281,7 +281,7 @@ void Pstream::scatterList
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toBelow(Pstream::scheduled, belowID);
|
||||
OPstream toBelow(UPstream::scheduled, belowID);
|
||||
|
||||
// Send data destined for all other processors below belowID
|
||||
forAll(notBelowLeaves, leafI)
|
||||
@ -305,13 +305,13 @@ void Pstream::scatterList
|
||||
template <class T>
|
||||
void Pstream::scatterList(List<T>& Values)
|
||||
{
|
||||
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
|
||||
{
|
||||
scatterList(Pstream::linearCommunication(), Values);
|
||||
scatterList(UPstream::linearCommunication(), Values);
|
||||
}
|
||||
else
|
||||
{
|
||||
scatterList(Pstream::treeCommunication(), Values);
|
||||
scatterList(UPstream::treeCommunication(), Values);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Namespace
|
||||
InNamespace
|
||||
Foam
|
||||
|
||||
Description
|
||||
@ -35,8 +35,6 @@ Description
|
||||
|
||||
#include "mathematicalConstants.H"
|
||||
|
||||
using namespace Foam::constant::mathematical;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
@ -47,13 +45,13 @@ namespace Foam
|
||||
//- Conversion from degrees to radians
|
||||
inline scalar degToRad(const scalar deg)
|
||||
{
|
||||
return (deg*pi/180.0);
|
||||
return (deg * constant::mathematical::pi/180.0);
|
||||
}
|
||||
|
||||
//- Conversion from radians to degrees
|
||||
inline scalar radToDeg(const scalar rad)
|
||||
{
|
||||
return (rad*180.0/pi);
|
||||
return (rad * 180.0/constant::mathematical::pi);
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -78,8 +78,7 @@ public:
|
||||
// Note: this does not initialise the coefficients or the source.
|
||||
simpleMatrix(const label);
|
||||
|
||||
//- Construct given size and initial values for the
|
||||
// coefficients and source
|
||||
//- Construct given size and initial values for coefficients and source
|
||||
simpleMatrix(const label, const scalar, const Type&);
|
||||
|
||||
//- Construct from components
|
||||
|
||||
@ -229,11 +229,7 @@ void processorPointPatch::initPatchPatchPoints()
|
||||
|
||||
// Send the patchPatchPoints to the neighbouring processor
|
||||
|
||||
OPstream toNeighbProc
|
||||
(
|
||||
Pstream::blocking,
|
||||
neighbProcNo()
|
||||
);
|
||||
OPstream toNeighbProc(Pstream::blocking, neighbProcNo());
|
||||
|
||||
toNeighbProc
|
||||
<< ppmp.size() // number of points for checking
|
||||
@ -252,11 +248,7 @@ void processorPointPatch::initPatchPatchPoints()
|
||||
void Foam::processorPointPatch::calcPatchPatchPoints()
|
||||
{
|
||||
// Get the patchPatchPoints from the neighbouring processor
|
||||
IPstream fromNeighbProc
|
||||
(
|
||||
Pstream::blocking,
|
||||
neighbProcNo()
|
||||
);
|
||||
IPstream fromNeighbProc(Pstream::blocking, neighbProcNo());
|
||||
|
||||
label nbrNPoints(readLabel(fromNeighbProc));
|
||||
labelListList patchPatchPoints(fromNeighbProc);
|
||||
|
||||
@ -381,7 +381,13 @@ Foam::mapDistribute::mapDistribute
|
||||
}
|
||||
|
||||
subMap_.setSize(Pstream::nProcs());
|
||||
exchange(wantedRemoteElements, subMap_);
|
||||
labelListList sendSizes;
|
||||
Pstream::exchange<labelList, label>
|
||||
(
|
||||
wantedRemoteElements,
|
||||
subMap_,
|
||||
sendSizes
|
||||
);
|
||||
|
||||
// Renumber elements
|
||||
forAll(elements, i)
|
||||
@ -528,7 +534,13 @@ Foam::mapDistribute::mapDistribute
|
||||
}
|
||||
|
||||
subMap_.setSize(Pstream::nProcs());
|
||||
exchange(wantedRemoteElements, subMap_);
|
||||
labelListList sendSizes;
|
||||
Pstream::exchange<labelList, label>
|
||||
(
|
||||
wantedRemoteElements,
|
||||
subMap_,
|
||||
sendSizes
|
||||
);
|
||||
|
||||
// Renumber elements
|
||||
forAll(cellCells, cellI)
|
||||
|
||||
@ -93,39 +93,8 @@ class mapDistribute
|
||||
mutable autoPtr<List<labelPair> > schedulePtr_;
|
||||
|
||||
|
||||
//- Exchange data. sendBuf[procI] : data to send to processor procI
|
||||
// To be moved into Pstream.
|
||||
template<class T>
|
||||
static void exchange
|
||||
(
|
||||
const List<List<T> >& sendBuf,
|
||||
List<List<T> >& recvBuf
|
||||
);
|
||||
|
||||
public:
|
||||
|
||||
// Public classes
|
||||
|
||||
//- combineReduce operator for lists. Used for counting.
|
||||
class listEq
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
template<class T>
|
||||
void operator()(T& x, const T& y) const
|
||||
{
|
||||
forAll(y, i)
|
||||
{
|
||||
if (y[i].size())
|
||||
{
|
||||
x[i] = y[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
|
||||
@ -25,6 +25,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Pstream.H"
|
||||
#include "PstreamBuffers.H"
|
||||
#include "PstreamCombineReduceOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
@ -185,17 +186,9 @@ void Foam::mapDistribute::distribute
|
||||
{
|
||||
if (!contiguous<T>())
|
||||
{
|
||||
// 1. convert to contiguous buffer
|
||||
// 2. send buffer
|
||||
// 3. receive buffer
|
||||
// 4. read from buffer into List<T>
|
||||
PstreamBuffers pBuffs(Pstream::nonBlocking);
|
||||
|
||||
List<List<char> > sendFields(Pstream::nProcs());
|
||||
labelListList allNTrans(Pstream::nProcs());
|
||||
labelList& nsTransPs = allNTrans[Pstream::myProcNo()];
|
||||
nsTransPs.setSize(Pstream::nProcs(), 0);
|
||||
|
||||
// Stream data into sendField buffers
|
||||
// Stream data into buffer
|
||||
for (label domain = 0; domain < Pstream::nProcs(); domain++)
|
||||
{
|
||||
const labelList& map = subMap[domain];
|
||||
@ -203,66 +196,13 @@ void Foam::mapDistribute::distribute
|
||||
if (domain != Pstream::myProcNo() && map.size())
|
||||
{
|
||||
// Put data into send buffer
|
||||
OPstream toDomain(Pstream::nonBlocking, domain);
|
||||
UOPstream toDomain(domain, pBuffs);
|
||||
toDomain << UIndirectList<T>(field, map);
|
||||
|
||||
// Store the size
|
||||
nsTransPs[domain] = toDomain.bufPosition();
|
||||
|
||||
// Transfer buffer out
|
||||
sendFields[domain].transfer(toDomain.buf());
|
||||
toDomain.bufPosition() = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Send sizes across
|
||||
combineReduce(allNTrans, listEq());
|
||||
|
||||
// Start sending buffers
|
||||
for (label domain = 0; domain < Pstream::nProcs(); domain++)
|
||||
{
|
||||
const labelList& map = subMap[domain];
|
||||
|
||||
if (domain != Pstream::myProcNo() && map.size())
|
||||
{
|
||||
OPstream::write
|
||||
(
|
||||
Pstream::nonBlocking,
|
||||
domain,
|
||||
reinterpret_cast<const char*>
|
||||
(
|
||||
sendFields[domain].begin()
|
||||
),
|
||||
nsTransPs[domain]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up receives from neighbours
|
||||
|
||||
PtrList<IPstream> fromSlave(Pstream::nProcs());
|
||||
|
||||
for (label domain = 0; domain < Pstream::nProcs(); domain++)
|
||||
{
|
||||
const labelList& map = constructMap[domain];
|
||||
|
||||
if (domain != Pstream::myProcNo() && map.size())
|
||||
{
|
||||
// Start receiving
|
||||
fromSlave.set
|
||||
(
|
||||
domain,
|
||||
new IPstream
|
||||
(
|
||||
Pstream::nonBlocking,
|
||||
domain,
|
||||
allNTrans[domain][Pstream::myProcNo()]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Start receiving
|
||||
pBuffs.finishedSends();
|
||||
|
||||
{
|
||||
// Set up 'send' to myself
|
||||
@ -285,10 +225,6 @@ void Foam::mapDistribute::distribute
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Wait till all finished
|
||||
Pstream::waitRequests();
|
||||
|
||||
// Consume
|
||||
for (label domain = 0; domain < Pstream::nProcs(); domain++)
|
||||
{
|
||||
@ -296,7 +232,8 @@ void Foam::mapDistribute::distribute
|
||||
|
||||
if (domain != Pstream::myProcNo() && map.size())
|
||||
{
|
||||
List<T> recvField(fromSlave[domain]);
|
||||
UIPstream str(domain, pBuffs);
|
||||
List<T> recvField(str);
|
||||
|
||||
if (recvField.size() != map.size())
|
||||
{
|
||||
@ -322,9 +259,6 @@ void Foam::mapDistribute::distribute
|
||||
{
|
||||
field[map[i]] = recvField[i];
|
||||
}
|
||||
|
||||
// Delete receive buffer
|
||||
fromSlave.set(domain, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -618,17 +552,10 @@ void Foam::mapDistribute::distribute
|
||||
{
|
||||
if (!contiguous<T>())
|
||||
{
|
||||
// 1. convert to contiguous buffer
|
||||
// 2. send buffer
|
||||
// 3. receive buffer
|
||||
// 4. read from buffer into List<T>
|
||||
//XXXXXX
|
||||
PstreamBuffers pBuffs(Pstream::nonBlocking);
|
||||
|
||||
List<List<char> > sendFields(Pstream::nProcs());
|
||||
labelListList allNTrans(Pstream::nProcs());
|
||||
labelList& nsTransPs = allNTrans[Pstream::myProcNo()];
|
||||
nsTransPs.setSize(Pstream::nProcs());
|
||||
|
||||
// Stream data into sendField buffers
|
||||
// Stream data into buffer
|
||||
for (label domain = 0; domain < Pstream::nProcs(); domain++)
|
||||
{
|
||||
const labelList& map = subMap[domain];
|
||||
@ -636,65 +563,13 @@ void Foam::mapDistribute::distribute
|
||||
if (domain != Pstream::myProcNo() && map.size())
|
||||
{
|
||||
// Put data into send buffer
|
||||
OPstream toDomain(Pstream::nonBlocking, domain);
|
||||
UOPstream toDomain(domain, pBuffs);
|
||||
toDomain << UIndirectList<T>(field, map);
|
||||
|
||||
// Store the size
|
||||
nsTransPs[domain] = toDomain.bufPosition();
|
||||
|
||||
// Transfer buffer out
|
||||
sendFields[domain].transfer(toDomain.buf());
|
||||
toDomain.bufPosition() = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Send sizes across
|
||||
combineReduce(allNTrans, listEq());
|
||||
|
||||
// Start sending buffers
|
||||
for (label domain = 0; domain < Pstream::nProcs(); domain++)
|
||||
{
|
||||
const labelList& map = subMap[domain];
|
||||
|
||||
if (domain != Pstream::myProcNo() && map.size())
|
||||
{
|
||||
OPstream::write
|
||||
(
|
||||
Pstream::nonBlocking,
|
||||
domain,
|
||||
reinterpret_cast<const char*>
|
||||
(
|
||||
sendFields[domain].begin()
|
||||
),
|
||||
nsTransPs[domain]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up receives from neighbours
|
||||
|
||||
PtrList<IPstream> fromSlave(Pstream::nProcs());
|
||||
|
||||
for (label domain = 0; domain < Pstream::nProcs(); domain++)
|
||||
{
|
||||
const labelList& map = constructMap[domain];
|
||||
|
||||
if (domain != Pstream::myProcNo() && map.size())
|
||||
{
|
||||
// Start receiving
|
||||
fromSlave.set
|
||||
(
|
||||
domain,
|
||||
new IPstream
|
||||
(
|
||||
Pstream::nonBlocking,
|
||||
domain,
|
||||
allNTrans[domain][Pstream::myProcNo()]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Start receiving
|
||||
pBuffs.finishedSends();
|
||||
|
||||
{
|
||||
// Set up 'send' to myself
|
||||
@ -715,7 +590,7 @@ void Foam::mapDistribute::distribute
|
||||
|
||||
|
||||
// Wait till all finished
|
||||
Pstream::waitRequests();
|
||||
UPstream::waitRequests();
|
||||
|
||||
// Consume
|
||||
for (label domain = 0; domain < Pstream::nProcs(); domain++)
|
||||
@ -724,7 +599,8 @@ void Foam::mapDistribute::distribute
|
||||
|
||||
if (domain != Pstream::myProcNo() && map.size())
|
||||
{
|
||||
List<T> recvField(fromSlave[domain]);
|
||||
UIPstream str(domain, pBuffs);
|
||||
List<T> recvField(str);
|
||||
|
||||
if (recvField.size() != map.size())
|
||||
{
|
||||
@ -750,9 +626,6 @@ void Foam::mapDistribute::distribute
|
||||
{
|
||||
cop(field[map[i]], recvField[i]);
|
||||
}
|
||||
|
||||
// Delete receive buffer
|
||||
fromSlave.set(domain, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -796,7 +669,7 @@ void Foam::mapDistribute::distribute
|
||||
if (domain != Pstream::myProcNo() && map.size())
|
||||
{
|
||||
recvFields[domain].setSize(map.size());
|
||||
IPstream::read
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::nonBlocking,
|
||||
domain,
|
||||
@ -886,78 +759,4 @@ void Foam::mapDistribute::distribute
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::mapDistribute::exchange
|
||||
(
|
||||
const List<List<T> >& sendBuf,
|
||||
List<List<T> >& recvBuf
|
||||
)
|
||||
{
|
||||
if (!contiguous<T>())
|
||||
{
|
||||
FatalErrorIn("mapDistribute::exchange(..)")
|
||||
<< "Not contiguous" << exit(FatalError);
|
||||
}
|
||||
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
|
||||
// Determine sizes
|
||||
// ~~~~~~~~~~~~~~~
|
||||
|
||||
labelListList allNTrans(Pstream::nProcs());
|
||||
allNTrans[Pstream::myProcNo()].setSize(Pstream::nProcs());
|
||||
|
||||
forAll(allNTrans, procI)
|
||||
{
|
||||
allNTrans[Pstream::myProcNo()][procI] = sendBuf[procI].size();
|
||||
}
|
||||
combineReduce(allNTrans, listEq());
|
||||
|
||||
|
||||
// Set up receives
|
||||
// ~~~~~~~~~~~~~~~
|
||||
|
||||
recvBuf.setSize(Pstream::nProcs());
|
||||
forAll(recvBuf, procI)
|
||||
{
|
||||
if (procI != Pstream::myProcNo())
|
||||
{
|
||||
recvBuf[procI].setSize(allNTrans[procI][Pstream::myProcNo()]);
|
||||
IPstream::read
|
||||
(
|
||||
Pstream::nonBlocking,
|
||||
procI,
|
||||
reinterpret_cast<char*>(recvBuf[procI].begin()),
|
||||
recvBuf[procI].byteSize()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up sends
|
||||
// ~~~~~~~~~~~~
|
||||
|
||||
forAll(sendBuf, procI)
|
||||
{
|
||||
if (procI != Pstream::myProcNo())
|
||||
{
|
||||
OPstream::write
|
||||
(
|
||||
Pstream::nonBlocking,
|
||||
procI,
|
||||
reinterpret_cast<const char*>(sendBuf[procI].begin()),
|
||||
sendBuf[procI].byteSize()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for completion
|
||||
Pstream::waitRequests();
|
||||
}
|
||||
|
||||
// Do myself
|
||||
recvBuf[Pstream::myProcNo()] = sendBuf[Pstream::myProcNo()];
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -402,11 +402,7 @@ void Foam::syncTools::syncPointMap
|
||||
{
|
||||
// Send to master
|
||||
{
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::blocking,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
OPstream toMaster(Pstream::blocking, Pstream::masterNo());
|
||||
toMaster << sharedPointValues;
|
||||
}
|
||||
// Receive merged values
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
Pstream.C
|
||||
IPread.C
|
||||
OPwrite.C
|
||||
UPstream.C
|
||||
UIPread.C
|
||||
UOPwrite.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/dummy/libPstream
|
||||
|
||||
@ -23,62 +23,66 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
Read token and binary block from IPstream
|
||||
Read from UIPstream
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "IPstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
#include "UIPstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IPstream::IPstream
|
||||
Foam::UIPstream::UIPstream
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int fromProcNo,
|
||||
const label bufSize,
|
||||
DynamicList<char>& externalBuf,
|
||||
const int tag,
|
||||
streamFormat format,
|
||||
versionNumber version
|
||||
)
|
||||
:
|
||||
Pstream(commsType, bufSize),
|
||||
UPstream(commsType),
|
||||
Istream(format, version),
|
||||
fromProcNo_(fromProcNo),
|
||||
externalBuf_(externalBuf),
|
||||
externalBufPosition_(0),
|
||||
tag_(tag),
|
||||
messageSize_(0)
|
||||
{
|
||||
notImplemented
|
||||
(
|
||||
"IPsream::IPstream"
|
||||
"("
|
||||
"const commsTypes,"
|
||||
"const int fromProcNo,"
|
||||
"const label bufSize,"
|
||||
"streamFormat, versionNumber"
|
||||
")"
|
||||
);
|
||||
notImplemented
|
||||
(
|
||||
"UIPstream::UIPstream"
|
||||
"("
|
||||
"const commsTypes,"
|
||||
"const int fromProcNo,"
|
||||
"DynamicList<char>&,"
|
||||
"const int tag,"
|
||||
"streamFormat, versionNumber"
|
||||
")"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
int Foam::IPstream::read
|
||||
Foam::label Foam::UIPstream::read
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int fromProcNo,
|
||||
char* buf,
|
||||
const std::streamsize bufSize
|
||||
const std::streamsize bufSize,
|
||||
const int tag
|
||||
)
|
||||
{
|
||||
notImplemented
|
||||
(
|
||||
"IPstream::read"
|
||||
"UIPstream::read"
|
||||
"("
|
||||
"const commsTypes,"
|
||||
"const int fromProcNo,"
|
||||
"char* buf,"
|
||||
"const label bufSize"
|
||||
"const label bufSize,"
|
||||
"const int tag"
|
||||
")"
|
||||
);
|
||||
|
||||
@ -27,41 +27,32 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "OPstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::OPstream::~OPstream()
|
||||
{
|
||||
notImplemented("OPstream::~OPstream()");
|
||||
}
|
||||
|
||||
#include "UOPstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::OPstream::write
|
||||
bool Foam::UOPstream::write
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int toProcNo,
|
||||
const char* buf,
|
||||
const std::streamsize bufSize
|
||||
const std::streamsize bufSize,
|
||||
const int tag
|
||||
)
|
||||
{
|
||||
notImplemented
|
||||
(
|
||||
"IPstream::write"
|
||||
"("
|
||||
"const commsTypes commsType,"
|
||||
"const int fromProcNo,"
|
||||
"char* buf,"
|
||||
"const label bufSize"
|
||||
")"
|
||||
);
|
||||
notImplemented
|
||||
(
|
||||
"UOPstream::write"
|
||||
"("
|
||||
"const commsTypes commsType,"
|
||||
"const int fromProcNo,"
|
||||
"char* buf,"
|
||||
"const label bufSize,"
|
||||
"const int tag"
|
||||
")"
|
||||
);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -24,20 +24,18 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Pstream.H"
|
||||
#include "UPstream.H"
|
||||
#include "PstreamReduceOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::Pstream::addValidParOptions(HashTable<string>& validParOptions)
|
||||
void Foam::UPstream::addValidParOptions(HashTable<string>& validParOptions)
|
||||
{}
|
||||
|
||||
|
||||
bool Foam::Pstream::init(int& argc, char**& argv)
|
||||
bool Foam::UPstream::init(int& argc, char**& argv)
|
||||
{
|
||||
FatalErrorIn("Pstream::init(int& argc, char**& argv)")
|
||||
FatalErrorIn("UPstream::init(int& argc, char**& argv)")
|
||||
<< "Trying to use the dummy Pstream library." << nl
|
||||
<< "This dummy library cannot be used in parallel mode"
|
||||
<< Foam::exit(FatalError);
|
||||
@ -46,15 +44,15 @@ bool Foam::Pstream::init(int& argc, char**& argv)
|
||||
}
|
||||
|
||||
|
||||
void Foam::Pstream::exit(int errnum)
|
||||
void Foam::UPstream::exit(int errnum)
|
||||
{
|
||||
notImplemented("Pstream::exit(int errnum)");
|
||||
notImplemented("UPstream::exit(int errnum)");
|
||||
}
|
||||
|
||||
|
||||
void Foam::Pstream::abort()
|
||||
void Foam::UPstream::abort()
|
||||
{
|
||||
notImplemented("Pstream::abort()");
|
||||
notImplemented("UPstream::abort()");
|
||||
}
|
||||
|
||||
|
||||
@ -63,13 +61,13 @@ void Foam::reduce(scalar&, const sumOp<scalar>&)
|
||||
|
||||
|
||||
|
||||
void Foam::Pstream::waitRequests()
|
||||
void Foam::UPstream::waitRequests()
|
||||
{}
|
||||
|
||||
|
||||
bool Foam::Pstream::finishedRequest(const label i)
|
||||
bool Foam::UPstream::finishedRequest(const label i)
|
||||
{
|
||||
notImplemented("Pstream::finishedRequest()");
|
||||
notImplemented("UPstream::finishedRequest()");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
OPwrite.C
|
||||
IPread.C
|
||||
Pstream.C
|
||||
UOPwrite.C
|
||||
UIPread.C
|
||||
UPstream.C
|
||||
PstreamGlobals.C
|
||||
|
||||
LIB = $(FOAM_MPI_LIBBIN)/libPstream
|
||||
|
||||
@ -23,91 +23,161 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
Read token and binary block from IPstream
|
||||
Read from UIPstream
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "mpi.h"
|
||||
|
||||
#include "IPstream.H"
|
||||
#include "UIPstream.H"
|
||||
#include "PstreamGlobals.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// Outstanding non-blocking operations.
|
||||
//! @cond fileScope
|
||||
//Foam::DynamicList<MPI_Request> IPstream_outstandingRequests_;
|
||||
//! @endcond fileScope
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IPstream::IPstream
|
||||
Foam::UIPstream::UIPstream
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int fromProcNo,
|
||||
const label bufSize,
|
||||
DynamicList<char>& externalBuf,
|
||||
const int tag,
|
||||
streamFormat format,
|
||||
versionNumber version
|
||||
)
|
||||
:
|
||||
Pstream(commsType, bufSize),
|
||||
UPstream(commsType),
|
||||
Istream(format, version),
|
||||
fromProcNo_(fromProcNo),
|
||||
externalBuf_(externalBuf),
|
||||
externalBufPosition_(0),
|
||||
tag_(tag),
|
||||
messageSize_(0)
|
||||
{
|
||||
setOpened();
|
||||
setGood();
|
||||
|
||||
MPI_Status status;
|
||||
|
||||
// Cannot use buf_.size() since appends a few bytes extra
|
||||
label realBufSize = bufSize;
|
||||
|
||||
// If the buffer size is not specified, probe the incomming message
|
||||
// and set it
|
||||
if (!bufSize)
|
||||
if (commsType == UPstream::nonBlocking)
|
||||
{
|
||||
if (commsType == nonBlocking)
|
||||
// Message is already received into externalBuf
|
||||
}
|
||||
else
|
||||
{
|
||||
MPI_Status status;
|
||||
|
||||
label wantedSize = externalBuf_.capacity();
|
||||
|
||||
// If the buffer size is not specified, probe the incomming message
|
||||
// and set it
|
||||
if (!wantedSize)
|
||||
{
|
||||
MPI_Probe(procID(fromProcNo_), tag_, MPI_COMM_WORLD, &status);
|
||||
MPI_Get_count(&status, MPI_BYTE, &messageSize_);
|
||||
|
||||
externalBuf_.setCapacity(messageSize_);
|
||||
wantedSize = messageSize_;
|
||||
}
|
||||
|
||||
messageSize_ = UIPstream::read
|
||||
(
|
||||
commsType,
|
||||
fromProcNo_,
|
||||
externalBuf_.begin(),
|
||||
wantedSize,
|
||||
tag_
|
||||
);
|
||||
|
||||
// Set addressed size. Leave actual allocated memory intact.
|
||||
externalBuf_.setSize(messageSize_);
|
||||
|
||||
if (!messageSize_)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"IPstream::IPstream(const commsTypes, const int, "
|
||||
"const label, streamFormat, versionNumber)"
|
||||
) << "Can use nonBlocking mode only with pre-allocated buffers"
|
||||
"UIPstream::UIPstream(const commsTypes, const int, "
|
||||
"DynamicList<char>&, streamFormat, versionNumber)"
|
||||
) << "read failed"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MPI_Probe(procID(fromProcNo_), msgType(), MPI_COMM_WORLD, &status);
|
||||
MPI_Get_count(&status, MPI_BYTE, &messageSize_);
|
||||
|
||||
buf_.setSize(messageSize_);
|
||||
realBufSize = buf_.size();
|
||||
Foam::UIPstream::UIPstream(const int fromProcNo, PstreamBuffers& buffers)
|
||||
:
|
||||
UPstream(buffers.commsType_),
|
||||
Istream(buffers.format_, buffers.version_),
|
||||
fromProcNo_(fromProcNo),
|
||||
externalBuf_(buffers.recvBuf_[fromProcNo]),
|
||||
externalBufPosition_(0),
|
||||
tag_(buffers.tag_),
|
||||
messageSize_(0)
|
||||
{
|
||||
if (commsType() != UPstream::scheduled && !buffers.finishedSendsCalled_)
|
||||
{
|
||||
FatalErrorIn("UIPstream::UIPstream(const int, PstreamBuffers&)")
|
||||
<< "PstreamBuffers::finishedSends() never called." << endl
|
||||
<< "Please call PstreamBuffers::finishedSends() after doing"
|
||||
<< " all your sends (using UOPstream) and before doing any"
|
||||
<< " receives (using UIPstream)" << Foam::exit(FatalError);
|
||||
}
|
||||
|
||||
messageSize_ = read(commsType, fromProcNo_, buf_.begin(), realBufSize);
|
||||
setOpened();
|
||||
setGood();
|
||||
|
||||
if (!messageSize_)
|
||||
if (commsType() == UPstream::nonBlocking)
|
||||
{
|
||||
FatalErrorIn
|
||||
// Message is already received into externalBuf
|
||||
}
|
||||
else
|
||||
{
|
||||
MPI_Status status;
|
||||
|
||||
label wantedSize = externalBuf_.capacity();
|
||||
|
||||
// If the buffer size is not specified, probe the incomming message
|
||||
// and set it
|
||||
if (!wantedSize)
|
||||
{
|
||||
MPI_Probe(procID(fromProcNo_), tag_, MPI_COMM_WORLD, &status);
|
||||
MPI_Get_count(&status, MPI_BYTE, &messageSize_);
|
||||
|
||||
externalBuf_.setCapacity(messageSize_);
|
||||
wantedSize = messageSize_;
|
||||
}
|
||||
|
||||
messageSize_ = UIPstream::read
|
||||
(
|
||||
"IPstream::IPstream(const commsTypes, const int, "
|
||||
"const label, streamFormat, versionNumber)"
|
||||
) << "read failed"
|
||||
<< Foam::abort(FatalError);
|
||||
commsType(),
|
||||
fromProcNo_,
|
||||
externalBuf_.begin(),
|
||||
wantedSize,
|
||||
tag_
|
||||
);
|
||||
|
||||
// Set addressed size. Leave actual allocated memory intact.
|
||||
externalBuf_.setSize(messageSize_);
|
||||
|
||||
if (!messageSize_)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"UIPstream::UIPstream(const int, PstreamBuffers&)"
|
||||
) << "read failed"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::IPstream::read
|
||||
Foam::label Foam::UIPstream::read
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int fromProcNo,
|
||||
char* buf,
|
||||
const std::streamsize bufSize
|
||||
const std::streamsize bufSize,
|
||||
const int tag
|
||||
)
|
||||
{
|
||||
if (commsType == blocking || commsType == scheduled)
|
||||
@ -122,7 +192,7 @@ Foam::label Foam::IPstream::read
|
||||
bufSize,
|
||||
MPI_PACKED,
|
||||
procID(fromProcNo),
|
||||
msgType(),
|
||||
tag,
|
||||
MPI_COMM_WORLD,
|
||||
&status
|
||||
)
|
||||
@ -130,7 +200,7 @@ Foam::label Foam::IPstream::read
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"IPstream::read"
|
||||
"UIPstream::read"
|
||||
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
|
||||
) << "MPI_Recv cannot receive incomming message"
|
||||
<< Foam::abort(FatalError);
|
||||
@ -148,7 +218,7 @@ Foam::label Foam::IPstream::read
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"IPstream::read"
|
||||
"UIPstream::read"
|
||||
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
|
||||
) << "buffer (" << label(bufSize)
|
||||
<< ") not large enough for incomming message ("
|
||||
@ -170,7 +240,7 @@ Foam::label Foam::IPstream::read
|
||||
bufSize,
|
||||
MPI_PACKED,
|
||||
procID(fromProcNo),
|
||||
msgType(),
|
||||
tag,
|
||||
MPI_COMM_WORLD,
|
||||
&request
|
||||
)
|
||||
@ -178,7 +248,7 @@ Foam::label Foam::IPstream::read
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"IPstream::read"
|
||||
"UIPstream::read"
|
||||
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
|
||||
) << "MPI_Recv cannot start non-blocking receive"
|
||||
<< Foam::abort(FatalError);
|
||||
@ -195,7 +265,7 @@ Foam::label Foam::IPstream::read
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"IPstream::read"
|
||||
"UIPstream::read"
|
||||
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
|
||||
) << "Unsupported communications type " << commsType
|
||||
<< Foam::abort(FatalError);
|
||||
@ -205,6 +275,4 @@ Foam::label Foam::IPstream::read
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -29,54 +29,18 @@ Description
|
||||
|
||||
#include "mpi.h"
|
||||
|
||||
#include "OPstream.H"
|
||||
#include "UOPstream.H"
|
||||
#include "PstreamGlobals.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::OPstream::~OPstream()
|
||||
{
|
||||
if (commsType_ == nonBlocking)
|
||||
{
|
||||
// alloc nonBlocking only if empty buffer. This denotes the buffer
|
||||
// having been transfered out.
|
||||
if (bufPosition_ > 0)
|
||||
{
|
||||
FatalErrorIn("OPstream::~OPstream()")
|
||||
<< "OPstream contains buffer so cannot be used with nonBlocking"
|
||||
<< " since destructor would destroy buffer whilst possibly"
|
||||
<< " still sending." << Foam::abort(FatalError);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if
|
||||
(
|
||||
!write
|
||||
(
|
||||
commsType_,
|
||||
toProcNo_,
|
||||
buf_.begin(),
|
||||
bufPosition_
|
||||
)
|
||||
)
|
||||
{
|
||||
FatalErrorIn("OPstream::~OPstream()")
|
||||
<< "MPI cannot send outgoing message"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::OPstream::write
|
||||
bool Foam::UOPstream::write
|
||||
(
|
||||
const commsTypes commsType,
|
||||
const int toProcNo,
|
||||
const char* buf,
|
||||
const std::streamsize bufSize
|
||||
const std::streamsize bufSize,
|
||||
const int tag
|
||||
)
|
||||
{
|
||||
bool transferFailed = true;
|
||||
@ -89,7 +53,7 @@ bool Foam::OPstream::write
|
||||
bufSize,
|
||||
MPI_PACKED,
|
||||
procID(toProcNo),
|
||||
msgType(),
|
||||
tag,
|
||||
MPI_COMM_WORLD
|
||||
);
|
||||
}
|
||||
@ -101,7 +65,7 @@ bool Foam::OPstream::write
|
||||
bufSize,
|
||||
MPI_PACKED,
|
||||
procID(toProcNo),
|
||||
msgType(),
|
||||
tag,
|
||||
MPI_COMM_WORLD
|
||||
);
|
||||
}
|
||||
@ -115,7 +79,7 @@ bool Foam::OPstream::write
|
||||
bufSize,
|
||||
MPI_PACKED,
|
||||
procID(toProcNo),
|
||||
msgType(),
|
||||
tag,
|
||||
MPI_COMM_WORLD,
|
||||
&request
|
||||
);
|
||||
@ -126,8 +90,9 @@ bool Foam::OPstream::write
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"OPstream::write"
|
||||
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
|
||||
"UOPstream::write"
|
||||
"(const int fromProcNo, char* buf, std::streamsize bufSize"
|
||||
", const int)"
|
||||
) << "Unsupported communications type " << commsType
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
@ -26,7 +26,7 @@ License
|
||||
|
||||
#include "mpi.h"
|
||||
|
||||
#include "Pstream.H"
|
||||
#include "UPstream.H"
|
||||
#include "PstreamReduceOps.H"
|
||||
#include "OSspecific.H"
|
||||
#include "PstreamGlobals.H"
|
||||
@ -50,7 +50,7 @@ License
|
||||
// valid parallel options vary between implementations, but flag common ones.
|
||||
// if they are not removed by MPI_Init(), the subsequent argument processing
|
||||
// will notice that they are wrong
|
||||
void Foam::Pstream::addValidParOptions(HashTable<string>& validParOptions)
|
||||
void Foam::UPstream::addValidParOptions(HashTable<string>& validParOptions)
|
||||
{
|
||||
validParOptions.insert("np", "");
|
||||
validParOptions.insert("p4pg", "PI file");
|
||||
@ -62,7 +62,7 @@ void Foam::Pstream::addValidParOptions(HashTable<string>& validParOptions)
|
||||
}
|
||||
|
||||
|
||||
bool Foam::Pstream::init(int& argc, char**& argv)
|
||||
bool Foam::UPstream::init(int& argc, char**& argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
|
||||
@ -72,8 +72,8 @@ bool Foam::Pstream::init(int& argc, char**& argv)
|
||||
|
||||
if (numprocs <= 1)
|
||||
{
|
||||
FatalErrorIn("Pstream::init(int& argc, char**& argv)")
|
||||
<< "bool Pstream::init(int& argc, char**& argv) : "
|
||||
FatalErrorIn("UPstream::init(int& argc, char**& argv)")
|
||||
<< "bool IPstream::init(int& argc, char**& argv) : "
|
||||
"attempt to run parallel on 1 processor"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
@ -101,8 +101,8 @@ bool Foam::Pstream::init(int& argc, char**& argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn("Pstream::init(int& argc, char**& argv)")
|
||||
<< "Pstream::init(int& argc, char**& argv) : "
|
||||
FatalErrorIn("UPstream::init(int& argc, char**& argv)")
|
||||
<< "UPstream::init(int& argc, char**& argv) : "
|
||||
<< "environment variable MPI_BUFFER_SIZE not defined"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
@ -122,7 +122,7 @@ bool Foam::Pstream::init(int& argc, char**& argv)
|
||||
}
|
||||
|
||||
|
||||
void Foam::Pstream::exit(int errnum)
|
||||
void Foam::UPstream::exit(int errnum)
|
||||
{
|
||||
# ifndef SGIMPI
|
||||
int size;
|
||||
@ -136,10 +136,10 @@ void Foam::Pstream::exit(int errnum)
|
||||
label n = PstreamGlobals::outstandingRequests_.size();
|
||||
PstreamGlobals::outstandingRequests_.clear();
|
||||
|
||||
WarningIn("Pstream::exit(int)")
|
||||
WarningIn("UPstream::exit(int)")
|
||||
<< "There are still " << n << " outstanding MPI_Requests." << endl
|
||||
<< "This means that your code exited before doing a"
|
||||
<< " Pstream::waitRequests()." << endl
|
||||
<< " UPstream::waitRequests()." << endl
|
||||
<< "This should not happen for a normal code exit."
|
||||
<< endl;
|
||||
}
|
||||
@ -156,7 +156,7 @@ void Foam::Pstream::exit(int errnum)
|
||||
}
|
||||
|
||||
|
||||
void Foam::Pstream::abort()
|
||||
void Foam::UPstream::abort()
|
||||
{
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
}
|
||||
@ -164,19 +164,19 @@ void Foam::Pstream::abort()
|
||||
|
||||
void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
{
|
||||
if (!Pstream::parRun())
|
||||
if (!UPstream::parRun())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Pstream::nProcs() <= Pstream::nProcsSimpleSum)
|
||||
if (UPstream::nProcs() <= UPstream::nProcsSimpleSum)
|
||||
{
|
||||
if (Pstream::master())
|
||||
if (UPstream::master())
|
||||
{
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
int slave=UPstream::firstSlave();
|
||||
slave<=UPstream::lastSlave();
|
||||
slave++
|
||||
)
|
||||
{
|
||||
@ -189,8 +189,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
&value,
|
||||
1,
|
||||
MPI_SCALAR,
|
||||
Pstream::procID(slave),
|
||||
Pstream::msgType(),
|
||||
UPstream::procID(slave),
|
||||
UPstream::msgType(),
|
||||
MPI_COMM_WORLD,
|
||||
MPI_STATUS_IGNORE
|
||||
)
|
||||
@ -215,8 +215,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
&Value,
|
||||
1,
|
||||
MPI_SCALAR,
|
||||
Pstream::procID(Pstream::masterNo()),
|
||||
Pstream::msgType(),
|
||||
UPstream::procID(UPstream::masterNo()),
|
||||
UPstream::msgType(),
|
||||
MPI_COMM_WORLD
|
||||
)
|
||||
)
|
||||
@ -230,12 +230,12 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
}
|
||||
|
||||
|
||||
if (Pstream::master())
|
||||
if (UPstream::master())
|
||||
{
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
int slave=UPstream::firstSlave();
|
||||
slave<=UPstream::lastSlave();
|
||||
slave++
|
||||
)
|
||||
{
|
||||
@ -246,8 +246,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
&Value,
|
||||
1,
|
||||
MPI_SCALAR,
|
||||
Pstream::procID(slave),
|
||||
Pstream::msgType(),
|
||||
UPstream::procID(slave),
|
||||
UPstream::msgType(),
|
||||
MPI_COMM_WORLD
|
||||
)
|
||||
)
|
||||
@ -269,8 +269,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
&Value,
|
||||
1,
|
||||
MPI_SCALAR,
|
||||
Pstream::procID(Pstream::masterNo()),
|
||||
Pstream::msgType(),
|
||||
UPstream::procID(UPstream::masterNo()),
|
||||
UPstream::msgType(),
|
||||
MPI_COMM_WORLD,
|
||||
MPI_STATUS_IGNORE
|
||||
)
|
||||
@ -291,8 +291,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
Value = sum;
|
||||
|
||||
/*
|
||||
int myProcNo = Pstream::myProcNo();
|
||||
int nProcs = Pstream::nProcs();
|
||||
int myProcNo = UPstream::myProcNo();
|
||||
int nProcs = UPstream::nProcs();
|
||||
|
||||
//
|
||||
// receive from children
|
||||
@ -321,8 +321,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
&value,
|
||||
1,
|
||||
MPI_SCALAR,
|
||||
Pstream::procID(childProcId),
|
||||
Pstream::msgType(),
|
||||
UPstream::procID(childProcId),
|
||||
UPstream::msgType(),
|
||||
MPI_COMM_WORLD,
|
||||
MPI_STATUS_IGNORE
|
||||
)
|
||||
@ -346,7 +346,7 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
//
|
||||
// send and receive from parent
|
||||
//
|
||||
if (!Pstream::master())
|
||||
if (!UPstream::master())
|
||||
{
|
||||
int parentId = myProcNo - (myProcNo % thisLevelOffset);
|
||||
|
||||
@ -357,8 +357,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
&Value,
|
||||
1,
|
||||
MPI_SCALAR,
|
||||
Pstream::procID(parentId),
|
||||
Pstream::msgType(),
|
||||
UPstream::procID(parentId),
|
||||
UPstream::msgType(),
|
||||
MPI_COMM_WORLD
|
||||
)
|
||||
)
|
||||
@ -377,8 +377,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
&Value,
|
||||
1,
|
||||
MPI_SCALAR,
|
||||
Pstream::procID(parentId),
|
||||
Pstream::msgType(),
|
||||
UPstream::procID(parentId),
|
||||
UPstream::msgType(),
|
||||
MPI_COMM_WORLD,
|
||||
MPI_STATUS_IGNORE
|
||||
)
|
||||
@ -413,8 +413,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
&Value,
|
||||
1,
|
||||
MPI_SCALAR,
|
||||
Pstream::procID(childProcId),
|
||||
Pstream::msgType(),
|
||||
UPstream::procID(childProcId),
|
||||
UPstream::msgType(),
|
||||
MPI_COMM_WORLD
|
||||
)
|
||||
)
|
||||
@ -436,7 +436,7 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
|
||||
}
|
||||
|
||||
|
||||
void Foam::Pstream::waitRequests()
|
||||
void Foam::UPstream::waitRequests()
|
||||
{
|
||||
if (PstreamGlobals::outstandingRequests_.size())
|
||||
{
|
||||
@ -452,7 +452,7 @@ void Foam::Pstream::waitRequests()
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Pstream::waitRequests()"
|
||||
"UPstream::waitRequests()"
|
||||
) << "MPI_Waitall returned with error" << Foam::endl;
|
||||
}
|
||||
|
||||
@ -461,13 +461,13 @@ void Foam::Pstream::waitRequests()
|
||||
}
|
||||
|
||||
|
||||
bool Foam::Pstream::finishedRequest(const label i)
|
||||
bool Foam::UPstream::finishedRequest(const label i)
|
||||
{
|
||||
if (i >= PstreamGlobals::outstandingRequests_.size())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Pstream::finishedRequest(const label)"
|
||||
"UPstream::finishedRequest(const label)"
|
||||
) << "There are " << PstreamGlobals::outstandingRequests_.size()
|
||||
<< " outstanding send requests and you are asking for i=" << i
|
||||
<< nl
|
||||
@ -55,9 +55,9 @@ namespace Foam
|
||||
class ifEqEqOp
|
||||
{
|
||||
public:
|
||||
void operator()(label x, const label y) const
|
||||
void operator()(label& x, const label y) const
|
||||
{
|
||||
x = (x==y) ? x : value;
|
||||
x = (x == y) ? x : value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -26,8 +26,6 @@ License
|
||||
|
||||
#include "processorFvPatchField.H"
|
||||
#include "processorFvPatch.H"
|
||||
#include "IPstream.H"
|
||||
#include "OPstream.H"
|
||||
#include "demandDrivenData.H"
|
||||
#include "transformField.H"
|
||||
|
||||
|
||||
@ -227,7 +227,7 @@ Foam::fvMatrix<Type>::fvMatrix
|
||||
);
|
||||
}
|
||||
|
||||
// Update the boundary coefficients of psi without changing it's event No.
|
||||
// Update the boundary coefficients of psi without changing its event No.
|
||||
GeometricField<Type, fvPatchField, volMesh>& psiRef =
|
||||
const_cast<GeometricField<Type, fvPatchField, volMesh>&>(psi_);
|
||||
|
||||
|
||||
@ -27,9 +27,6 @@ Description
|
||||
list of selected cells, it creates the mesh consisting only of the
|
||||
desired cells, with the mapping list for points, faces, and cells.
|
||||
|
||||
MJ 23/03/05 on coupled faces change the patch of the face to the
|
||||
oldInternalFaces patch.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fvMeshSubset.H"
|
||||
|
||||
@ -98,29 +98,6 @@ void Foam::Cloud<ParticleType>::deleteParticle(ParticleType& p)
|
||||
}
|
||||
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class combineNsTransPs
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
void operator()(labelListList& x, const labelListList& y) const
|
||||
{
|
||||
forAll(y, i)
|
||||
{
|
||||
if (y[i].size())
|
||||
{
|
||||
x[i] = y[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
template<class ParticleType>
|
||||
template<class TrackingData>
|
||||
void Foam::Cloud<ParticleType>::move(TrackingData& td)
|
||||
@ -196,7 +173,7 @@ void Foam::Cloud<ParticleType>::move(TrackingData& td)
|
||||
// processor patches for all the processors
|
||||
labelListList allNTrans(Pstream::nProcs());
|
||||
allNTrans[Pstream::myProcNo()] = nsTransPs;
|
||||
combineReduce(allNTrans, combineNsTransPs());
|
||||
combineReduce(allNTrans, UPstream::listEq());
|
||||
|
||||
transfered = false;
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ protected:
|
||||
scalar volumeTotal_;
|
||||
|
||||
//- Total mass to inject [kg]
|
||||
const scalar massTotal_;
|
||||
scalar massTotal_;
|
||||
|
||||
//- Total mass injected to date [kg]
|
||||
scalar massInjected_;
|
||||
|
||||
@ -124,11 +124,12 @@ Foam::PatchInjection<CloudType>::PatchInjection
|
||||
|
||||
label patchSize = cellOwners_.size();
|
||||
label totalPatchSize = patchSize;
|
||||
reduce(totalPatchSize, sumOp<scalar>());
|
||||
fraction_ = patchSize/totalPatchSize;
|
||||
reduce(totalPatchSize, sumOp<label>());
|
||||
fraction_ = scalar(patchSize)/totalPatchSize;
|
||||
|
||||
// Set total volume to inject
|
||||
// Set total volume/mass to inject
|
||||
this->volumeTotal_ = fraction_*volumeFlowRate_().integrate(0.0, duration_);
|
||||
this->massTotal_ *= fraction_;
|
||||
}
|
||||
|
||||
|
||||
@ -165,10 +166,19 @@ void Foam::PatchInjection<CloudType>::setPositionAndCell
|
||||
label& cellOwner
|
||||
)
|
||||
{
|
||||
label cellI = this->owner().rndGen().integer(0, cellOwners_.size() - 1);
|
||||
if (cellOwners_.size() > 0)
|
||||
{
|
||||
label cellI = this->owner().rndGen().integer(0, cellOwners_.size() - 1);
|
||||
|
||||
cellOwner = cellOwners_[cellI];
|
||||
position = this->owner().mesh().C()[cellOwner];
|
||||
cellOwner = cellOwners_[cellI];
|
||||
position = this->owner().mesh().C()[cellOwner];
|
||||
}
|
||||
else
|
||||
{
|
||||
cellOwner = -1;
|
||||
// dummy position
|
||||
position = pTraits<vector>::max;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -170,7 +170,7 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Take this referredCell object that has already had it's transform
|
||||
//- Take this referredCell object that has already had its transform
|
||||
// calculated and refer it on again, retaining same source info.
|
||||
referredCell reRefer
|
||||
(
|
||||
|
||||
@ -38,74 +38,70 @@ Foam::pointField Foam::BSpline::findKnots
|
||||
const vector& sndend
|
||||
)
|
||||
{
|
||||
label newnKnots(allknots.size() + 2);
|
||||
label NKnots(allknots.size());
|
||||
pointField newknots(newnKnots);
|
||||
const label NKnots = allknots.size();
|
||||
|
||||
// set up 1/6 and 2/3 which are the matrix elements throughout most
|
||||
// of the matrix
|
||||
|
||||
register scalar oneSixth = 1.0/6.0;
|
||||
register scalar twoThird = 2.0/3.0;
|
||||
register const scalar oneSixth = 1.0/6.0;
|
||||
register const scalar twoThird = 2.0/3.0;
|
||||
|
||||
simpleMatrix<vector> M(newnKnots, 0, vector::zero);
|
||||
simpleMatrix<vector> M(NKnots+2, 0, vector::zero);
|
||||
|
||||
// set up the matrix
|
||||
|
||||
M[0][0] = -0.5*scalar(NKnots - 1);
|
||||
M[0][2] = 0.5*scalar(NKnots - 1);
|
||||
|
||||
for (register label i=1; i<newnKnots-1; i++)
|
||||
for (register label i = 1; i <= NKnots; i++)
|
||||
{
|
||||
M[i][i-1] = oneSixth;
|
||||
M[i][i] = twoThird;
|
||||
M[i][i+1] = oneSixth;
|
||||
}
|
||||
|
||||
M[newnKnots - 1][newnKnots - 3] = -0.5*scalar(NKnots - 1);
|
||||
M[newnKnots - 1][newnKnots - 1] = 0.5*scalar(NKnots - 1);
|
||||
M[NKnots+1][NKnots-1] = -0.5*scalar(NKnots - 1);
|
||||
M[NKnots+1][NKnots+1] = 0.5*scalar(NKnots - 1);
|
||||
|
||||
// set up the vector
|
||||
|
||||
for (label i=1; i<=NKnots; i++)
|
||||
for (register label i = 1; i <= NKnots; i++)
|
||||
{
|
||||
M.source()[i] = allknots[i-1];
|
||||
}
|
||||
|
||||
// set the gradients at the two ends
|
||||
// set the gradients at the ends:
|
||||
|
||||
if (mag(fstend)<1e-8)
|
||||
if (mag(fstend) < 1e-8)
|
||||
{
|
||||
// set to the default : forward differences on the end knots
|
||||
// default : forward differences on the end knots
|
||||
M.source()[0] = allknots[1] - allknots[0];
|
||||
M.source()[0] /= mag(M.source()[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// use the gradient vector provided
|
||||
M.source()[0] = fstend/mag(fstend);
|
||||
}
|
||||
|
||||
if (mag(sndend)<1e-8)
|
||||
{
|
||||
// default : forward differences on the end knots
|
||||
M.source()[NKnots+1] = M.source()[NKnots-1] - M.source()[NKnots];
|
||||
M.source()[NKnots+1] /= mag(M.source()[NKnots+1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// set to the gradient vectors provided
|
||||
M.source()[0] = fstend/mag(fstend);
|
||||
// use the gradient vector provided
|
||||
M.source()[NKnots+1] = sndend/mag(sndend);
|
||||
}
|
||||
|
||||
|
||||
// invert the equation to find the control knots
|
||||
|
||||
newknots = M.solve();
|
||||
|
||||
return newknots;
|
||||
return M.solve();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::BSpline::BSpline(const pointField& Knots)
|
||||
:
|
||||
spline(findKnots(Knots))
|
||||
{}
|
||||
|
||||
|
||||
Foam::BSpline::BSpline
|
||||
(
|
||||
const pointField& Knots,
|
||||
|
||||
@ -56,8 +56,8 @@ class BSpline
|
||||
pointField findKnots
|
||||
(
|
||||
const pointField&,
|
||||
const vector& fstend = vector::zero,
|
||||
const vector& sndend = vector::zero
|
||||
const vector& fstend,
|
||||
const vector& sndend
|
||||
);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
@ -71,15 +71,12 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
BSpline(const pointField& knots);
|
||||
|
||||
//- Construct from components
|
||||
BSpline
|
||||
(
|
||||
const pointField& knots,
|
||||
const vector& fstend,
|
||||
const vector& sndend
|
||||
const vector& fstend = vector::zero,
|
||||
const vector& sndend = vector::zero
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ Foam::cylindricalCS Foam::arcEdge::calcAngle()
|
||||
angle_ = radToDeg(acos(tmp));
|
||||
|
||||
// check if the vectors define an exterior or an interior arcEdge
|
||||
if (((r1 ^ r2)&(r1 ^ r3)) < 0.0)
|
||||
if (((r1 ^ r2)&(r1 ^ r3)) < 0.0)
|
||||
{
|
||||
angle_ = 360.0 - angle_;
|
||||
}
|
||||
|
||||
@ -36,20 +36,6 @@ namespace Foam
|
||||
addToRunTimeSelectionTable(curvedEdge, polySplineEdge, Istream);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
//! @cond fileScope
|
||||
inline label nsize(const label otherKnotsSize, const label nBetweenKnots)
|
||||
{
|
||||
return otherKnotsSize*(1 + nBetweenKnots) + nBetweenKnots + 2;
|
||||
}
|
||||
//! @endcond fileScope
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
// intervening : returns a list of the points making up the polyLineEdge
|
||||
@ -68,18 +54,25 @@ Foam::pointField Foam::polySplineEdge::intervening
|
||||
const vector& sndend
|
||||
)
|
||||
{
|
||||
BSpline spl(knotlist(points_, start_, end_, otherknots), fstend, sndend);
|
||||
BSpline spl
|
||||
(
|
||||
knotlist(points_, start_, end_, otherknots),
|
||||
fstend,
|
||||
sndend
|
||||
);
|
||||
|
||||
label nSize(nsize(otherknots.size(), nBetweenKnots));
|
||||
const label nSize
|
||||
(
|
||||
otherknots.size() * (1 + nBetweenKnots) + nBetweenKnots + 2
|
||||
);
|
||||
|
||||
pointField ans(nSize);
|
||||
|
||||
label N = spl.nKnots();
|
||||
scalar init = 1.0/(N - 1);
|
||||
scalar interval = (N - scalar(3))/N;
|
||||
const label NKnots = spl.nKnots();
|
||||
const scalar init = 1.0/(NKnots - 1);
|
||||
scalar interval = (NKnots - scalar(3.0))/NKnots;
|
||||
interval /= otherknots.size() + 1;
|
||||
interval /= nBetweenKnots + 1;
|
||||
|
||||
pointField ans(nSize);
|
||||
ans[0] = points_[start_];
|
||||
|
||||
register scalar index(init);
|
||||
@ -135,17 +128,8 @@ Foam::polySplineEdge::polySplineEdge
|
||||
vector fstend(is);
|
||||
vector sndend(is);
|
||||
|
||||
controlPoints_.setSize(nsize(otherKnots_.size(), nInterKnots));
|
||||
// why does this need to be here (to avoid a crash)?
|
||||
// 'intervening' uses BSpline to solve the new points
|
||||
// it seems to be going badly there
|
||||
distances_.setSize(controlPoints_.size());
|
||||
|
||||
controlPoints_ = intervening(otherKnots_, nInterKnots, fstend, sndend);
|
||||
calcDistances();
|
||||
|
||||
// Info<< "polyLine[" << start_ << " " << end_
|
||||
// << "] controlPoints " << controlPoints_ << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -26,17 +26,9 @@ License
|
||||
|
||||
#include "spline.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::spline::spline(const pointField& knotPoints)
|
||||
:
|
||||
knots_(knotPoints)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::scalar Foam::spline::B(const scalar tau) const
|
||||
Foam::scalar Foam::spline::B(const scalar tau)
|
||||
{
|
||||
if (tau <= -2.0 || tau >= 2.0)
|
||||
{
|
||||
@ -44,7 +36,7 @@ Foam::scalar Foam::spline::B(const scalar tau) const
|
||||
}
|
||||
else if (tau <= -1.0)
|
||||
{
|
||||
return pow((2.0 + tau),3.0)/6.0;
|
||||
return pow((2.0 + tau), 3.0)/6.0;
|
||||
}
|
||||
else if (tau <= 0.0)
|
||||
{
|
||||
@ -56,7 +48,7 @@ Foam::scalar Foam::spline::B(const scalar tau) const
|
||||
}
|
||||
else if (tau <= 2.0)
|
||||
{
|
||||
return pow((2.0 - tau),3.0)/6.0;
|
||||
return pow((2.0 - tau), 3.0)/6.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -70,13 +62,23 @@ Foam::scalar Foam::spline::B(const scalar tau) const
|
||||
}
|
||||
|
||||
|
||||
Foam::vector Foam::spline::position(const scalar mu1) const
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::spline::spline(const pointField& knotPoints)
|
||||
:
|
||||
knots_(knotPoints)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::vector Foam::spline::position(const scalar mu) const
|
||||
{
|
||||
vector loc(vector::zero);
|
||||
|
||||
for (register label i=0; i<knots_.size(); i++)
|
||||
for (register label i=0; i < knots_.size(); i++)
|
||||
{
|
||||
loc += B((knots_.size() - 1)*mu1 - i)*knots_[i];
|
||||
loc += B((knots_.size() - 1)*mu - i)*knots_[i];
|
||||
}
|
||||
|
||||
return loc;
|
||||
|
||||
@ -27,6 +27,7 @@ Class
|
||||
|
||||
Description
|
||||
Define a basic spline on nKnots knots.
|
||||
|
||||
The spline does not go anywhere near these knots
|
||||
(will act as a base type for various splines that will have real uses)
|
||||
|
||||
@ -59,7 +60,7 @@ class spline
|
||||
// Private Member Functions
|
||||
|
||||
//- Blending function for constructing spline
|
||||
scalar B(const scalar) const;
|
||||
static scalar B(const scalar);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
spline(const spline&);
|
||||
|
||||
@ -63,11 +63,8 @@ Foam::scalar Foam::EulerImplicit<CompType, ThermoType>::solve
|
||||
const scalar dt
|
||||
) const
|
||||
{
|
||||
scalar pf, cf, pr, cr;
|
||||
label lRef, rRef;
|
||||
|
||||
label nSpecie = this->model_.nSpecie();
|
||||
simpleMatrix<scalar> RR(nSpecie);
|
||||
const label nSpecie = this->model_.nSpecie();
|
||||
simpleMatrix<scalar> RR(nSpecie, 0, 0);
|
||||
|
||||
for (label i=0; i<nSpecie; i++)
|
||||
{
|
||||
@ -83,6 +80,9 @@ Foam::scalar Foam::EulerImplicit<CompType, ThermoType>::solve
|
||||
{
|
||||
const Reaction<ThermoType>& R = this->model_.reactions()[i];
|
||||
|
||||
scalar pf, cf, pr, cr;
|
||||
label lRef, rRef;
|
||||
|
||||
scalar omegai = this->model_.omega
|
||||
(
|
||||
R, c, T, p, pf, cf, lRef, pr, cr, rRef
|
||||
@ -132,7 +132,7 @@ Foam::scalar Foam::EulerImplicit<CompType, ThermoType>::solve
|
||||
|
||||
// estimate the next time step
|
||||
scalar tMin = GREAT;
|
||||
label nEqns = this->model_.nEqns();
|
||||
const label nEqns = this->model_.nEqns();
|
||||
scalarField c1(nEqns, 0.0);
|
||||
|
||||
for (label i=0; i<nSpecie; i++)
|
||||
|
||||
42
tutorials/multiphase/interDyMFoam/ras/floatingObject/0.org/U
Normal file
42
tutorials/multiphase/interDyMFoam/ras/floatingObject/0.org/U
Normal file
@ -0,0 +1,42 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format binary;
|
||||
class volVectorField;
|
||||
location "0";
|
||||
object U;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
dimensions [0 1 -1 0 0 0 0];
|
||||
|
||||
internalField uniform (0 0 0);
|
||||
|
||||
boundaryField
|
||||
{
|
||||
stationaryWalls
|
||||
{
|
||||
type fixedValue;
|
||||
value uniform (0 0 0);
|
||||
}
|
||||
atmosphere
|
||||
{
|
||||
type pressureInletOutletVelocity;
|
||||
value uniform (0 0 0);
|
||||
}
|
||||
floatingObject
|
||||
{
|
||||
type movingWallVelocity;
|
||||
value uniform (0 0 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,41 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class volScalarField;
|
||||
location "0";
|
||||
object alpha1;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
dimensions [0 0 0 0 0 0 0];
|
||||
|
||||
internalField uniform 0;
|
||||
|
||||
boundaryField
|
||||
{
|
||||
stationaryWalls
|
||||
{
|
||||
type zeroGradient;
|
||||
}
|
||||
atmosphere
|
||||
{
|
||||
type inletOutlet;
|
||||
inletValue uniform 0;
|
||||
value uniform 0;
|
||||
}
|
||||
floatingObject
|
||||
{
|
||||
type zeroGradient;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,49 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class volScalarField;
|
||||
location "0";
|
||||
object epsilon;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
dimensions [0 2 -3 0 0 0 0];
|
||||
|
||||
internalField uniform 0.1;
|
||||
|
||||
boundaryField
|
||||
{
|
||||
stationaryWalls
|
||||
{
|
||||
type epsilonWallFunction;
|
||||
Cmu 0.09;
|
||||
kappa 0.41;
|
||||
E 9.8;
|
||||
value uniform 0.1;
|
||||
}
|
||||
atmosphere
|
||||
{
|
||||
type inletOutlet;
|
||||
inletValue uniform 0.1;
|
||||
value uniform 0.1;
|
||||
}
|
||||
floatingObject
|
||||
{
|
||||
type epsilonWallFunction;
|
||||
Cmu 0.09;
|
||||
kappa 0.41;
|
||||
E 9.8;
|
||||
value uniform 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
43
tutorials/multiphase/interDyMFoam/ras/floatingObject/0.org/k
Normal file
43
tutorials/multiphase/interDyMFoam/ras/floatingObject/0.org/k
Normal file
@ -0,0 +1,43 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class volScalarField;
|
||||
location "0";
|
||||
object k;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
dimensions [0 2 -2 0 0 0 0];
|
||||
|
||||
internalField uniform 0.1;
|
||||
|
||||
boundaryField
|
||||
{
|
||||
stationaryWalls
|
||||
{
|
||||
type kqRWallFunction;
|
||||
value uniform 0.1;
|
||||
}
|
||||
atmosphere
|
||||
{
|
||||
type inletOutlet;
|
||||
inletValue uniform 0.1;
|
||||
value uniform 0.1;
|
||||
}
|
||||
floatingObject
|
||||
{
|
||||
type kqRWallFunction;
|
||||
value uniform 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,48 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class volScalarField;
|
||||
location "0";
|
||||
object nut;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
dimensions [0 2 -1 0 0 0 0];
|
||||
|
||||
internalField uniform 0;
|
||||
|
||||
boundaryField
|
||||
{
|
||||
stationaryWalls
|
||||
{
|
||||
type nutkWallFunction;
|
||||
Cmu 0.09;
|
||||
kappa 0.41;
|
||||
E 9.8;
|
||||
value uniform 0;
|
||||
}
|
||||
atmosphere
|
||||
{
|
||||
type calculated;
|
||||
value uniform 0;
|
||||
}
|
||||
floatingObject
|
||||
{
|
||||
type nutkWallFunction;
|
||||
Cmu 0.09;
|
||||
kappa 0.41;
|
||||
E 9.8;
|
||||
value uniform 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
46
tutorials/multiphase/interDyMFoam/ras/floatingObject/0.org/p
Normal file
46
tutorials/multiphase/interDyMFoam/ras/floatingObject/0.org/p
Normal file
@ -0,0 +1,46 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: http://www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class volScalarField;
|
||||
object pd;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
dimensions [1 -1 -2 0 0 0 0];
|
||||
|
||||
internalField uniform 0;
|
||||
|
||||
boundaryField
|
||||
{
|
||||
stationaryWalls
|
||||
{
|
||||
type buoyantPressure;
|
||||
value uniform 0;
|
||||
}
|
||||
atmosphere
|
||||
{
|
||||
type totalPressure;
|
||||
p0 uniform 0;
|
||||
U U;
|
||||
phi phi;
|
||||
rho rho;
|
||||
psi none;
|
||||
gamma 1;
|
||||
value uniform 0;
|
||||
}
|
||||
floatingObject
|
||||
{
|
||||
type buoyantPressure;
|
||||
value uniform 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,51 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class pointVectorField;
|
||||
location "0.01";
|
||||
object pointDisplacement;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
dimensions [0 1 0 0 0 0 0];
|
||||
|
||||
internalField uniform (0 0 0);
|
||||
|
||||
boundaryField
|
||||
{
|
||||
stationaryWalls
|
||||
{
|
||||
type fixedValue;
|
||||
value uniform (0 0 0);
|
||||
}
|
||||
atmosphere
|
||||
{
|
||||
type fixedValue;
|
||||
value uniform (0 0 0);
|
||||
}
|
||||
floatingObject
|
||||
{
|
||||
type sixDoFRigidBodyDisplacement;
|
||||
centreOfMass (0.5 0.5 0.5);
|
||||
momentOfInertia (0.08622222 0.8622222 0.144);
|
||||
mass 9.6;
|
||||
rhoInf 1;
|
||||
Q (1 0 0 0 1 0 0 0 1);
|
||||
v (0 0 0);
|
||||
a (0 0 0);
|
||||
pi (0 0 0);
|
||||
tau (0 0 0);
|
||||
value uniform (0 0 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -20,7 +20,7 @@ makeMeshByCellSet()
|
||||
runApplication blockMesh
|
||||
makeMeshByCellSet 1 2
|
||||
runApplication subsetMesh -overwrite c0 -patch floatingObject
|
||||
cp -r 0.orig 0 > /dev/null 2>&1
|
||||
cp -r 0.org 0 > /dev/null 2>&1
|
||||
runApplication setFields
|
||||
runApplication $application
|
||||
|
||||
|
||||
Reference in New Issue
Block a user