Commit d7a2cc47 authored by Marcus Mohr's avatar Marcus Mohr
Browse files

Avoids doing two global MPI reduce ops in P2Function::getMaxMagnitude()

The initial implementation of P2Function::getMaxMagnitude() performs two
global MPI reduce operations. One in VertexDoFFunction::getMaxMagnitude()
and the second one in EdgeDoFFunction::getMaxMagnitude().

This commits adds to each of the above functions a second option parameter
bool mpiReduce, which defaults to true. P2Function::getMaxMagnitude()
invokes them with false and performs the global reduce itself.

We probably should do the same with P2Function::dot()?
parent 46a4ae27
Pipeline #9111 passed with stage
in 31 minutes and 50 seconds
......@@ -99,7 +99,7 @@ public:
const PrimitiveDataID< FunctionMemory< ValueType >, Edge> & getEdgeDataID() const { return edgeDataID_; }
const PrimitiveDataID< FunctionMemory< ValueType >, Face> & getFaceDataID() const { return faceDataID_; }
inline real_t getMaxMagnitude( uint_t level, DoFType flag = All );
inline real_t getMaxMagnitude( uint_t level, DoFType flag = All, bool mpiReduce = true );
private:
......@@ -305,7 +305,7 @@ inline void EdgeDoFFunction< ValueType >::enumerate_impl(uint_t level, uint_t& n
template< typename ValueType >
inline real_t EdgeDoFFunction< ValueType >::getMaxMagnitude( uint_t level, DoFType flag )
inline real_t EdgeDoFFunction< ValueType >::getMaxMagnitude( uint_t level, DoFType flag, bool mpiReduce )
{
real_t localMax = real_t(0.0);
......@@ -327,7 +327,11 @@ inline real_t EdgeDoFFunction< ValueType >::getMaxMagnitude( uint_t level, DoFTy
}
}
walberla::mpi::allReduceInplace( localMax, walberla::mpi::MAX, walberla::mpi::MPIManager::instance()->comm() );
if( mpiReduce )
{
walberla::mpi::allReduceInplace( localMax, walberla::mpi::MAX, walberla::mpi::MPIManager::instance()->comm() );
}
return localMax;
}
......
......@@ -75,7 +75,7 @@ public:
// TODO: write more general version(s)
inline real_t getMaxValue( uint_t level, DoFType flag = All );
inline real_t getMinValue( uint_t level, DoFType flag = All );
inline real_t getMaxMagnitude( uint_t level, DoFType flag = All );
inline real_t getMaxMagnitude( uint_t level, DoFType flag = All, bool mpiReduce = true );
inline uint_t getNumLocalDoFs ( const uint_t & level ) const;
inline uint_t getNumGlobalDoFs( const uint_t & level ) const;
......@@ -626,7 +626,7 @@ inline real_t VertexDoFFunction< ValueType >::getMaxValue( uint_t level, DoFType
template< typename ValueType >
inline real_t VertexDoFFunction< ValueType >::getMaxMagnitude( uint_t level, DoFType flag )
inline real_t VertexDoFFunction< ValueType >::getMaxMagnitude( uint_t level, DoFType flag, bool mpiReduce )
{
real_t localMax = real_t(0.0);
......@@ -651,7 +651,10 @@ inline real_t VertexDoFFunction< ValueType >::getMaxMagnitude( uint_t level, DoF
}
}
real_t globalMax = walberla::mpi::allReduce( localMax, walberla::mpi::MAX );
real_t globalMax = localMax;
if( mpiReduce ) {
globalMax = walberla::mpi::allReduce( localMax, walberla::mpi::MAX );
}
return globalMax;
}
......
......@@ -395,8 +395,11 @@ class P2Function : public Function< P2Function< ValueType > >
inline real_t getMaxMagnitude( uint_t level, DoFType flag = All )
{
real_t localMax = real_t(0.0);
localMax = std::max( localMax, vertexDoFFunction_->getMaxMagnitude( level, flag ) );
localMax = std::max( localMax, edgeDoFFunction_->getMaxMagnitude( level, flag ) );
localMax = std::max( localMax, vertexDoFFunction_->getMaxMagnitude( level, flag, false ) );
localMax = std::max( localMax, edgeDoFFunction_->getMaxMagnitude( level, flag, false ) );
walberla::mpi::allReduceInplace( localMax, walberla::mpi::MAX, walberla::mpi::MPIManager::instance()->comm() );
return localMax;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment