ENH: specialise bitOr<unsigned char> reduction

STYLE: remove extraneous parRun check before Pstream::combineReduce

- already handled by Pstream::combineReduce itself

STYLE: remove deprecated globalMeshData::ListPlusEqOp

- deprecated/superseded by ListOps::appendEqOp (2020-09)

STYLE: qualify stream format with IOstreamOption (easier to find)
This commit is contained in:
Mark Olesen 2023-07-18 08:54:34 +02:00
parent 95b820368c
commit 65cddb6120
17 changed files with 55 additions and 90 deletions

View File

@ -122,7 +122,12 @@ int main(int argc, char *argv[])
}
Pout<< "local procUsed " << procUsed << nl;
reduce(procUsed.data(), procUsed.size_data(), bitOrOp<unsigned>());
reduce
(
procUsed.data(),
procUsed.size_data(),
bitOrOp<unsigned int>()
);
Pout<< "reduce procUsed " << procUsed << nl;
// Identical size on all procs
@ -146,7 +151,12 @@ int main(int argc, char *argv[])
}
Pout<< "local uniform " << uniformity << nl;
reduce(uniformity.data(), uniformity.size_data(), bitOrOp<unsigned>());
reduce
(
uniformity.data(),
uniformity.size_data(),
bitOrOp<unsigned int>()
);
Pout<< "reduce uniform " << uniformity << nl;
}

View File

@ -30,11 +30,7 @@ if (doLagrangian)
nameOp<fileName>()
);
if (UPstream::parRun())
{
// Synchronise cloud names
Pstream::combineReduce(cloudNames, ListOps::uniqueEqOp<word>());
}
Pstream::combineReduce(cloudNames, ListOps::uniqueEqOp<word>());
Foam::sort(cloudNames); // Consistent order
for (const word& cloudName : cloudNames)

View File

@ -75,10 +75,7 @@ Foam::label Foam::particleTracksSampler::setTrackFields
{
wordList fieldNames = obr.names<IOField<Type>>();
if (Pstream::parRun())
{
Pstream::combineReduce(fieldNames, ListOps::uniqueEqOp<word>());
}
Pstream::combineReduce(fieldNames, ListOps::uniqueEqOp<word>());
for (const word& fieldName : fieldNames)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,7 +39,7 @@ void Foam::IOobjectList::checkObjectOrder
bool syncPar
)
{
if (syncPar && Pstream::parRun())
if (syncPar && UPstream::is_parallel())
{
wordList objectNames(objs.size());
@ -62,21 +62,21 @@ void Foam::IOobjectList::checkNameOrder
bool syncPar
)
{
if (syncPar && Pstream::parRun())
if (syncPar && UPstream::is_parallel())
{
wordList masterNames;
if (Pstream::master())
if (UPstream::master())
{
masterNames = objectNames;
}
Pstream::broadcast(masterNames);
if (objectNames != masterNames)
if (!UPstream::master() && (objectNames != masterNames))
{
FatalErrorInFunction
<< "Objects not synchronised across processors." << nl
<< "Master has " << flatOutput(masterNames) << nl
<< "Processor " << Pstream::myProcNo()
<< "Processor " << UPstream::myProcNo()
<< " has " << flatOutput(objectNames) << endl
<< exit(FatalError);
}
@ -86,12 +86,8 @@ void Foam::IOobjectList::checkNameOrder
void Foam::IOobjectList::syncNames(wordList& objNames)
{
if (Pstream::parRun())
{
// Synchronize names
Pstream::combineReduce(objNames, ListOps::uniqueEqOp<word>());
}
// Synchronize names
Pstream::combineReduce(objNames, ListOps::uniqueEqOp<word>());
Foam::sort(objNames); // Consistent order
}
@ -331,7 +327,7 @@ Foam::wordList Foam::IOobjectList::allNames() const
void Foam::IOobjectList::checkNames(const bool syncPar) const
{
if (syncPar && Pstream::parRun())
if (syncPar && UPstream::is_parallel())
{
wordList objNames(HashPtrTable<IOobject>::sortedToc());

View File

@ -382,7 +382,8 @@ Pstream_CommonReductions(uint64_t);
Pstream_FloatReductions(float);
Pstream_FloatReductions(double);
Pstream_BitwiseReductions(unsigned);
Pstream_BitwiseReductions(unsigned char);
Pstream_BitwiseReductions(unsigned int);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -494,7 +494,7 @@ Foam::Istream& Foam::UIPstreamBase::read(char* data, std::streamsize count)
Foam::Istream& Foam::UIPstreamBase::readRaw(char* data, std::streamsize count)
{
// No check for format() == BINARY since this is either done in the
// No check for IOstreamOption::BINARY since this is either done in the
// beginRawRead() method, or the caller knows what they are doing.
// Any alignment must have been done prior to this call
@ -505,7 +505,7 @@ Foam::Istream& Foam::UIPstreamBase::readRaw(char* data, std::streamsize count)
bool Foam::UIPstreamBase::beginRawRead()
{
if (format() != BINARY)
if (format() != IOstreamOption::BINARY)
{
FatalErrorInFunction
<< "stream format not binary"

View File

@ -346,7 +346,7 @@ Foam::Ostream& Foam::UOPstreamBase::write
std::streamsize count
)
{
if (format() != BINARY)
if (format() != IOstreamOption::BINARY)
{
FatalErrorInFunction
<< "stream format not binary"
@ -366,7 +366,7 @@ Foam::Ostream& Foam::UOPstreamBase::writeRaw
std::streamsize count
)
{
// No check for format() == BINARY since this is either done in the
// No check for IOstreamOption::BINARY since this is either done in the
// beginRawWrite() method, or the caller knows what they are doing.
// Previously aligned and sizes reserved via beginRawWrite()
@ -378,7 +378,7 @@ Foam::Ostream& Foam::UOPstreamBase::writeRaw
bool Foam::UOPstreamBase::beginRawWrite(std::streamsize count)
{
if (format() != BINARY)
if (format() != IOstreamOption::BINARY)
{
FatalErrorInFunction
<< "stream format not binary"

View File

@ -1061,7 +1061,7 @@ Foam::Istream& Foam::ISstream::readRaw(char* data, std::streamsize count)
bool Foam::ISstream::beginRawRead()
{
if (format() != BINARY)
if (format() != IOstreamOption::BINARY)
{
FatalIOErrorInFunction(*this)
<< "stream format not binary"

View File

@ -224,7 +224,7 @@ Foam::Ostream& Foam::OSstream::write(const char* data, std::streamsize count)
bool Foam::OSstream::beginRawWrite(std::streamsize count)
{
if (format() != BINARY)
if (format() != IOstreamOption::BINARY)
{
FatalIOErrorInFunction(*this)
<< "stream format not binary"
@ -251,7 +251,7 @@ Foam::Ostream& Foam::OSstream::writeRaw
std::streamsize count
)
{
// No check for format() == BINARY since this is either done in the
// No check for IOstreamOption::BINARY since this is either done in the
// beginRawWrite() method, or the caller knows what they are doing.
os_.write(data, count);

View File

@ -143,15 +143,14 @@ Foam::Ostream& Foam::OTstream::write(const double val)
Foam::Ostream& Foam::OTstream::write(const char* data, std::streamsize count)
{
if (format() != IOstreamOption::BINARY)
{
FatalErrorInFunction
<< "stream format not binary"
<< Foam::abort(FatalError);
}
// if (format() != IOstreamOption::BINARY)
// {
// FatalErrorInFunction
// << "stream format not binary"
// << Foam::abort(FatalError);
// }
NotImplemented;
return *this;
}
@ -162,26 +161,24 @@ Foam::Ostream& Foam::OTstream::writeRaw
std::streamsize count
)
{
// No check for format() == BINARY since this is either done in the
// No check for IOstreamOption::BINARY since this is either done in the
// beginRawWrite() method, or the caller knows what they are doing.
NotImplemented;
return *this;
}
bool Foam::OTstream::beginRawWrite(std::streamsize count)
{
if (format() != IOstreamOption::BINARY)
{
FatalErrorInFunction
<< "stream format not binary"
<< Foam::abort(FatalError);
}
// if (format() != IOstreamOption::BINARY)
// {
// FatalErrorInFunction
// << "stream format not binary"
// << Foam::abort(FatalError);
// }
NotImplemented;
return true;
}

View File

@ -59,7 +59,7 @@ Foam::IOstreamOption::formatEnum
if (!formatName.empty())
{
if (formatNames.found(formatName))
if (formatNames.contains(formatName))
{
return formatNames[formatName];
}

View File

@ -566,7 +566,7 @@ Foam::fileOperation::lookupAndCacheProcessorsPath
// 3 : mixed empty/non-empty directory (after reduce)
// Combines andOp<bool>() and orOp<bool>() in single operation
unsigned procDirsStatus = (procDirs.empty() ? 1u : 2u);
unsigned int procDirsStatus = (procDirs.empty() ? 1u : 2u);
if (debug)
{
@ -576,7 +576,7 @@ Foam::fileOperation::lookupAndCacheProcessorsPath
if (UPstream::parRun() && (!distributed() || syncPar))
{
reduce(procDirsStatus, bitOrOp<unsigned>()); // worldComm
reduce(procDirsStatus, bitOrOp<unsigned int>()); // worldComm
if (procDirsStatus == 3u)
{

View File

@ -606,34 +606,6 @@ public:
// full parallel analysis to determine shared points and
// boundaries.
void updateMesh();
// Housekeeping
//- Deprecated(2020-09) use ListOps::appendEqOp
// Uses a different template parameter
// \code
// globalMeshData::ListPlusEqOp<labelList>()
// ListOps::appendEqOp<label>()
// \endcode
//
// \deprecated(2020-09) - use ListOps::appendEqOp
template<class T>
struct ListPlusEqOp
{
FOAM_DEPRECATED_FOR(2020-09, "ListOps::appendEqOp")
void operator()(T& x, const T& y) const
{
label n = x.size();
x.setSize(x.size() + y.size());
forAll(y, i)
{
x[n++] = y[i];
}
}
};
};

View File

@ -223,7 +223,8 @@ Pstream_CommonReductions(uint64_t);
Pstream_FloatReductions(float);
Pstream_FloatReductions(double);
Pstream_BitwiseReductions(unsigned);
Pstream_BitwiseReductions(unsigned char);
Pstream_BitwiseReductions(unsigned int);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -311,7 +311,8 @@ Pstream_CommonReductions(uint64_t, MPI_UINT64_T);
Pstream_FloatReductions(float, MPI_FLOAT);
Pstream_FloatReductions(double, MPI_DOUBLE);
Pstream_BitwiseReductions(unsigned, MPI_UNSIGNED);
Pstream_BitwiseReductions(unsigned char, MPI_UNSIGNED_CHAR);
Pstream_BitwiseReductions(unsigned int, MPI_UNSIGNED);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -74,10 +74,7 @@ void Foam::areaWrite::performAction
fieldNames = areaMesh.thisDb().names<GeoField>(fieldSelection_);
// Synchronize names
if (Pstream::parRun())
{
Pstream::combineReduce(fieldNames, ListOps::uniqueEqOp<word>());
}
Pstream::combineReduce(fieldNames, ListOps::uniqueEqOp<word>());
Foam::sort(fieldNames); // Consistent order
}

View File

@ -237,10 +237,7 @@ void Foam::multiWorldConnections::createComms()
const label oldWarnComm = UPstream::commWarn(UPstream::commGlobal());
const label oldWorldComm = UPstream::commWorld(UPstream::commGlobal());
if (Pstream::parRun())
{
Pstream::combineReduce(allConnections, worldConnectBitOrEq());
}
Pstream::combineReduce(allConnections, worldConnectBitOrEq());
// Check for mismatched connections
label brokenConnections = 0;