mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -6,6 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
|
Copyright (C) 2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
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.
|
// Try whichProcID on a few borderline cases.
|
||||||
|
|
||||||
if (mesh.nCells() < 1)
|
if (mesh.nCells() < 1)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
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 * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, globalIndex& gi)
|
Foam::Istream& Foam::operator>>(Istream& is, globalIndex& gi)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2018-2019 OpenCFD Ltd.
|
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -53,7 +53,7 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declarations
|
// Forward Declarations
|
||||||
|
|
||||||
class globalIndex;
|
class globalIndex;
|
||||||
class labelRange;
|
class labelRange;
|
||||||
@ -81,7 +81,7 @@ class globalIndex
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Private data
|
// Private Data
|
||||||
|
|
||||||
//- Start of proci. Size is nProcs()+1. (so like CompactListList)
|
//- Start of proci. Size is nProcs()+1. (so like CompactListList)
|
||||||
labelList offsets_;
|
labelList offsets_;
|
||||||
@ -91,7 +91,7 @@ public:
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null
|
//- Default construct
|
||||||
globalIndex() = default;
|
globalIndex() = default;
|
||||||
|
|
||||||
//- Construct from local max size.
|
//- Construct from local max size.
|
||||||
@ -120,23 +120,26 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Check for null constructed or global sum == 0
|
//- Check for default constructed or global sum == 0
|
||||||
inline bool empty() const;
|
inline bool empty() const;
|
||||||
|
|
||||||
//- Const-access to the offsets
|
|
||||||
inline const labelList& offsets() const;
|
|
||||||
|
|
||||||
//- Global sum of localSizes
|
//- Global sum of localSizes
|
||||||
inline label size() const;
|
inline label size() const;
|
||||||
|
|
||||||
//- The local sizes
|
//- The local sizes
|
||||||
labelList sizes() const;
|
labelList sizes() const;
|
||||||
|
|
||||||
|
//- Global max of localSizes
|
||||||
|
inline label maxSize() const;
|
||||||
|
|
||||||
|
//- Const-access to the offsets
|
||||||
|
inline const labelList& offsets() const noexcept;
|
||||||
|
|
||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
|
|
||||||
//- Write-access to the offsets, for changing after construction
|
//- Write-access to the offsets, for changing after construction
|
||||||
inline labelList& offsets();
|
inline labelList& offsets() noexcept;
|
||||||
|
|
||||||
//- Reset from local size.
|
//- Reset from local size.
|
||||||
// Does communication with default communicator and message tag.
|
// Does communication with default communicator and message tag.
|
||||||
@ -153,6 +156,8 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Queries
|
||||||
|
|
||||||
// Queries relating to my processor (using world communicator)
|
// Queries relating to my processor (using world communicator)
|
||||||
|
|
||||||
//- My local start
|
//- My local start
|
||||||
@ -161,6 +166,9 @@ public:
|
|||||||
//- My local size
|
//- My local size
|
||||||
inline label localSize() const;
|
inline label localSize() const;
|
||||||
|
|
||||||
|
//- The max of localSizes, excluding current processor
|
||||||
|
inline label maxNonLocalSize() const;
|
||||||
|
|
||||||
//- Return start/size range of local processor data
|
//- Return start/size range of local processor data
|
||||||
inline labelRange range() const;
|
inline labelRange range() const;
|
||||||
|
|
||||||
@ -181,7 +189,7 @@ public:
|
|||||||
inline label toLocal(const label i) const;
|
inline label toLocal(const label i) const;
|
||||||
|
|
||||||
|
|
||||||
// Global queries
|
// Global (off-processor) queries
|
||||||
|
|
||||||
//- Start of proci data
|
//- Start of proci data
|
||||||
inline label offset(const label proci) const;
|
inline label offset(const label proci) const;
|
||||||
@ -192,6 +200,9 @@ public:
|
|||||||
//- Size of proci data
|
//- Size of proci data
|
||||||
inline label localSize(const label proci) const;
|
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
|
//- Return start/size range of proci data
|
||||||
inline labelRange range(const label proci) const;
|
inline labelRange range(const label proci) const;
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2018 OpenCFD Ltd.
|
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
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_;
|
return offsets_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::labelList& Foam::globalIndex::offsets()
|
inline Foam::labelList& Foam::globalIndex::offsets() noexcept
|
||||||
{
|
{
|
||||||
return offsets_;
|
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
|
inline Foam::labelRange Foam::globalIndex::range(const label proci) const
|
||||||
{
|
{
|
||||||
return labelRange(offsets_[proci], offsets_[proci+1] - offsets_[proci]);
|
return labelRange(offsets_[proci], offsets_[proci+1] - offsets_[proci]);
|
||||||
|
|||||||
Reference in New Issue
Block a user