ENH: add maxSize() and maxNonLocalSize() to globalIndex
- useful for establishing and preallocating a max buffer size when reading from sub-procs
This commit is contained in:
parent
56db12fca1
commit
86a2ae4f03
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -92,6 +93,11 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
Info<< "Max number of cells: " << globalNumbering.maxSize() << nl;
|
||||
Pout<< "nCells: "
|
||||
<< globalNumbering.localSize() << " Max off-processor: "
|
||||
<< globalNumbering.maxNonLocalSize() << nl;
|
||||
|
||||
// Try whichProcID on a few borderline cases.
|
||||
|
||||
if (mesh.nCells() < 1)
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -159,6 +159,30 @@ Foam::labelList Foam::globalIndex::sizes() const
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::globalIndex::maxNonLocalSize(const label proci) const
|
||||
{
|
||||
const label len = (offsets_.size() - 1);
|
||||
|
||||
if (len < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
label maxLen = 0;
|
||||
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
if (i != proci)
|
||||
{
|
||||
const label localLen = (offsets_[i+1] - offsets_[i]);
|
||||
maxLen = max(maxLen, localLen);
|
||||
}
|
||||
}
|
||||
|
||||
return maxLen;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Istream& Foam::operator>>(Istream& is, globalIndex& gi)
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -53,7 +53,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
// Forward Declarations
|
||||
|
||||
class globalIndex;
|
||||
class labelRange;
|
||||
@ -81,7 +81,7 @@ class globalIndex
|
||||
);
|
||||
|
||||
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Start of proci. Size is nProcs()+1. (so like CompactListList)
|
||||
labelList offsets_;
|
||||
@ -91,7 +91,7 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
//- Default construct
|
||||
globalIndex() = default;
|
||||
|
||||
//- Construct from local max size.
|
||||
@ -120,23 +120,26 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Check for null constructed or global sum == 0
|
||||
//- Check for default constructed or global sum == 0
|
||||
inline bool empty() const;
|
||||
|
||||
//- Const-access to the offsets
|
||||
inline const labelList& offsets() const;
|
||||
|
||||
//- Global sum of localSizes
|
||||
inline label size() const;
|
||||
|
||||
//- The local sizes
|
||||
labelList sizes() const;
|
||||
|
||||
//- Global max of localSizes
|
||||
inline label maxSize() const;
|
||||
|
||||
//- Const-access to the offsets
|
||||
inline const labelList& offsets() const noexcept;
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Write-access to the offsets, for changing after construction
|
||||
inline labelList& offsets();
|
||||
inline labelList& offsets() noexcept;
|
||||
|
||||
//- Reset from local size.
|
||||
// Does communication with default communicator and message tag.
|
||||
@ -153,6 +156,8 @@ public:
|
||||
);
|
||||
|
||||
|
||||
// Queries
|
||||
|
||||
// Queries relating to my processor (using world communicator)
|
||||
|
||||
//- My local start
|
||||
@ -161,6 +166,9 @@ public:
|
||||
//- My local size
|
||||
inline label localSize() const;
|
||||
|
||||
//- The max of localSizes, excluding current processor
|
||||
inline label maxNonLocalSize() const;
|
||||
|
||||
//- Return start/size range of local processor data
|
||||
inline labelRange range() const;
|
||||
|
||||
@ -181,7 +189,7 @@ public:
|
||||
inline label toLocal(const label i) const;
|
||||
|
||||
|
||||
// Global queries
|
||||
// Global (off-processor) queries
|
||||
|
||||
//- Start of proci data
|
||||
inline label offset(const label proci) const;
|
||||
@ -192,6 +200,9 @@ public:
|
||||
//- Size of proci data
|
||||
inline label localSize(const label proci) const;
|
||||
|
||||
//- The max of localSizes, excluding the specified processor
|
||||
label maxNonLocalSize(const label proci) const;
|
||||
|
||||
//- Return start/size range of proci data
|
||||
inline labelRange range(const label proci) const;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -73,13 +73,13 @@ inline bool Foam::globalIndex::empty() const
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::labelList& Foam::globalIndex::offsets() const
|
||||
inline const Foam::labelList& Foam::globalIndex::offsets() const noexcept
|
||||
{
|
||||
return offsets_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::labelList& Foam::globalIndex::offsets()
|
||||
inline Foam::labelList& Foam::globalIndex::offsets() noexcept
|
||||
{
|
||||
return offsets_;
|
||||
}
|
||||
@ -127,6 +127,19 @@ inline Foam::label Foam::globalIndex::localSize() const
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::globalIndex::maxSize() const
|
||||
{
|
||||
// Use out-of-range proci to avoid excluding any processor
|
||||
return maxNonLocalSize(-1);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::globalIndex::maxNonLocalSize() const
|
||||
{
|
||||
return maxNonLocalSize(Pstream::myProcNo());
|
||||
}
|
||||
|
||||
|
||||
inline Foam::labelRange Foam::globalIndex::range(const label proci) const
|
||||
{
|
||||
return labelRange(offsets_[proci], offsets_[proci+1] - offsets_[proci]);
|
||||
|
Loading…
Reference in New Issue
Block a user