Added template specialisation for reduce of bool

This commit is contained in:
Hrvoje Jasak 2016-09-23 18:41:03 +01:00
parent 4306c96365
commit 19ab01acb8
2 changed files with 133 additions and 5 deletions

View file

@ -682,8 +682,8 @@ void Foam::Pstream::abort()
void Foam::reduce void Foam::reduce
( (
scalar& Value, bool& Value,
const sumOp<scalar>& bop, const andOp<bool>& bop,
const int tag, const int tag,
const label comm const label comm
) )
@ -696,7 +696,67 @@ void Foam::reduce
error::printStack(Pout); error::printStack(Pout);
} }
allReduce(Value, 1, MPI_SCALAR, MPI_SUM, bop, tag, comm); // Note: C++ bool is a type separate from C and cannot be cast
// For safety and compatibility with compilers, convert bool to int
// to comply with MPI types. HJ, 23/Sep/2016
int intBool = 0;
if (Value)
{
intBool = 1;
}
allReduce(intBool, 1, MPI_INT, MPI_LAND, bop, tag, comm);
if (intBool > 0)
{
Value = true;
}
else
{
Value = false;
}
}
void Foam::reduce
(
bool& Value,
const orOp<bool>& bop,
const int tag,
const label comm
)
{
if (Pstream::warnComm != -1 && comm != Pstream::warnComm)
{
Pout<< "** reducing:" << Value << " with comm:" << comm
<< " warnComm:" << Pstream::warnComm
<< endl;
error::printStack(Pout);
}
// Note: C++ bool is a type separate from C and cannot be cast
// For safety and compatibility with compilers, convert bool to int
// to comply with MPI types. HJ, 23/Sep/2016
int intBool = 0;
if (Value)
{
intBool = 1;
}
allReduce(intBool, 1, MPI_INT, MPI_LOR, bop, tag, comm);
if (intBool > 0)
{
Value = true;
}
else
{
Value = false;
}
} }
@ -719,6 +779,45 @@ void Foam::reduce
} }
void Foam::reduce
(
scalar& Value,
const maxOp<scalar>& bop,
const int tag,
const label comm
)
{
if (Pstream::warnComm != -1 && comm != Pstream::warnComm)
{
Pout<< "** reducing:" << Value << " with comm:" << comm
<< " warnComm:" << Pstream::warnComm
<< endl;
error::printStack(Pout);
}
allReduce(Value, 1, MPI_SCALAR, MPI_MAX, bop, tag, comm);
}
void Foam::reduce
(
scalar& Value,
const sumOp<scalar>& bop,
const int tag,
const label comm
)
{
if (Pstream::warnComm != -1 && comm != Pstream::warnComm)
{
Pout<< "** reducing:" << Value << " with comm:" << comm
<< " warnComm:" << Pstream::warnComm
<< endl;
error::printStack(Pout);
}
allReduce(Value, 1, MPI_SCALAR, MPI_SUM, bop, tag, comm);
}
void Foam::reduce void Foam::reduce
( (
vector2D& Value, vector2D& Value,
@ -1050,7 +1149,7 @@ const Foam::debug::optimisationSwitch
Foam::Pstream::nProcsSimpleSum Foam::Pstream::nProcsSimpleSum
( (
"nProcsSimpleSum", "nProcsSimpleSum",
16 0
); );

View file

@ -139,7 +139,28 @@ void reduce
} }
// Insist there are specialisations for the common reductions of scalar(s) // Insist there are specialisations for the common reductions of bool
// See implementation notes on casting of a C++ bool into MPI_INT in
// Pstream.C HJ, 23/Sep/2016
void reduce
(
bool& Value,
const andOp<bool>& bop,
const int tag = Pstream::msgType(),
const label comm = Pstream::worldComm
);
void reduce
(
bool& Value,
const orOp<bool>& bop,
const int tag = Pstream::msgType(),
const label comm = Pstream::worldComm
);
// Insist there are specialisations for the common reductions of scalars
void reduce void reduce
( (
scalar& Value, scalar& Value,
@ -156,6 +177,14 @@ void reduce
const label comm = Pstream::worldComm const label comm = Pstream::worldComm
); );
void reduce
(
scalar& Value,
const maxOp<scalar>& bop,
const int tag = Pstream::msgType(),
const label comm = Pstream::worldComm
);
void reduce void reduce
( (
vector2D& Value, vector2D& Value,