Skip to content
Snippets Groups Projects
Commit c4fc897b authored by Gregor Weiss's avatar Gregor Weiss
Browse files

ENH: reduce Offsets

parent a66f5698
No related merge requests found
#include "Offsets.H"
Foam::Offsets::Offsets( label value, bool parRun ) {
set( value );
void Foam::Offsets::do_reduce() {
label offset = 0;
forAll(offsets_, procI)
{
label oldOffset = offset;
offset += offsets_[procI];
if (offset < oldOffset)
{
FatalErrorIn("Foam::Offsets")
<< "Overflow : sum of sizes " << offsets_
<< " exceeds capability of label (" << labelMax
<< "). Please recompile with larger datatype for label."
<< exit(FatalError);
}
offsets_[procI] = offset;
}
}
Foam::Offsets::Offsets( label value, bool parRun, bool reduce ) {
set( value, reduce );
}
void Foam::Offsets::set( Foam::label value ) {
void Foam::Offsets::set( Foam::label value, bool reduce ) {
offsets_[ Foam::Pstream::myProcNo() ] = value;
Foam::Pstream::gatherList( offsets_ );
Foam::Pstream::scatterList( offsets_ );
if ( reduce ) { do_reduce(); }
// If processor does not own corresponding
// mesh entities. Problem first arised with points.
for ( label proc = 1; proc < Foam::Pstream::nProcs(); ++proc ) {
......@@ -30,3 +51,5 @@ Foam::label Foam::Offsets::upperBound( Foam::label myProcNo ) const {
Foam::label Foam::Offsets::count( Foam::label myProcNo ) const {
return upperBound( myProcNo ) - lowerBound( myProcNo );
}
......@@ -8,15 +8,20 @@ namespace Foam
class Offsets {
labelList offsets_{ Pstream::nProcs(), 0 };
labelList offsets_{ labelList(Pstream::nProcs(), 0) };
void do_reduce();
public:
Offsets() = default;
explicit Offsets( label value, bool parRun = Pstream::parRun() );
explicit Offsets( label value,
bool parRun = Pstream::parRun(),
bool reduce = false );
void set( label value );
void set( label value,
bool reduce = false );
label lowerBound( label ) const;
label upperBound( label ) const;
......
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