From bd57627955a68bde0cf3eb1bd28a188d81951ebc Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 28 Aug 2025 14:33:18 +0200 Subject: [PATCH] ENH: extend bitSet functionality - num_blocks(), test_set() as per boost - broadcast(), reduceAnd(), reduceOr() to simplify parallel operations - matrix-like output for PackedList::writeList() BUG: Pstream::broadcastList() missing resize on sub-ranks - latent bug since it was unused in any OpenFOAM code --- applications/test/PackedList/Make/files | 2 +- ...{Test-PackedList.C => Test-PackedList.cxx} | 0 applications/test/bitSet1/Test-bitSet1.cxx | 3 + applications/test/bitSet2/Test-bitSet2.cxx | 4 +- .../parallel-chunks/Test-parallel-chunks.cxx | 22 +- .../parallel-comm0/Test-parallel-comm0.cxx | 52 ++-- .../parallel-comm3a/Test-parallel-comm3a.cxx | 4 +- .../parallel-comm3b/Test-parallel-comm3b.cxx | 4 +- .../test/parallel-nbx2/Test-parallel-nbx2.cxx | 4 +- .../containers/Bits/PackedList/PackedList.H | 28 +- .../containers/Bits/PackedList/PackedListI.H | 32 +-- .../containers/Bits/PackedList/PackedListIO.C | 36 ++- src/OpenFOAM/containers/Bits/bitSet/bitSet.C | 239 +++++++++++++++++- src/OpenFOAM/containers/Bits/bitSet/bitSet.H | 75 +++++- src/OpenFOAM/containers/Bits/bitSet/bitSetI.H | 32 ++- src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H | 3 + .../IOstreams/Pstreams/PstreamBroadcast.txx | 10 + 17 files changed, 433 insertions(+), 117 deletions(-) rename applications/test/PackedList/{Test-PackedList.C => Test-PackedList.cxx} (100%) diff --git a/applications/test/PackedList/Make/files b/applications/test/PackedList/Make/files index 93a37615fc..ec391bad6e 100644 --- a/applications/test/PackedList/Make/files +++ b/applications/test/PackedList/Make/files @@ -1,3 +1,3 @@ -Test-PackedList.C +Test-PackedList.cxx EXE = $(FOAM_USER_APPBIN)/Test-PackedList diff --git a/applications/test/PackedList/Test-PackedList.C b/applications/test/PackedList/Test-PackedList.cxx similarity index 100% rename from applications/test/PackedList/Test-PackedList.C rename to applications/test/PackedList/Test-PackedList.cxx diff --git a/applications/test/bitSet1/Test-bitSet1.cxx b/applications/test/bitSet1/Test-bitSet1.cxx index 08d5f47a2a..4c5df5ac32 100644 --- a/applications/test/bitSet1/Test-bitSet1.cxx +++ b/applications/test/bitSet1/Test-bitSet1.cxx @@ -142,6 +142,9 @@ int main(int argc, char *argv[]) Info<< "got: " << bset1 << nl << "and: " << bset2 << nl << "and: " << bset3 << nl; + + Info<< "=="; + bset3.writeList(Info, 10) << nl; // matrix-like output } } diff --git a/applications/test/bitSet2/Test-bitSet2.cxx b/applications/test/bitSet2/Test-bitSet2.cxx index 6b0675b836..98a4c59489 100644 --- a/applications/test/bitSet2/Test-bitSet2.cxx +++ b/applications/test/bitSet2/Test-bitSet2.cxx @@ -137,11 +137,11 @@ inline bool compare const std::string& expected ) { - const List& store = bitset.storage(); + const auto& store = bitset.storage(); std::string has; - for (label blocki=0; blocki < bitset.nBlocks(); ++blocki) + for (label blocki=0; blocki < bitset.num_blocks(); ++blocki) { has += toString(store[blocki]); } diff --git a/applications/test/parallel-chunks/Test-parallel-chunks.cxx b/applications/test/parallel-chunks/Test-parallel-chunks.cxx index 1975699889..78b1dce67e 100644 --- a/applications/test/parallel-chunks/Test-parallel-chunks.cxx +++ b/applications/test/parallel-chunks/Test-parallel-chunks.cxx @@ -185,9 +185,9 @@ int main(int argc, char *argv[]) } broadcast_chunks(input1); - Pstream::maxCommsSize = 33; + UPstream::maxCommsSize = 33; - args.readIfPresent("comms-size", Pstream::maxCommsSize); + args.readIfPresent("comms-size", UPstream::maxCommsSize); broadcast_chunks(input1); @@ -197,11 +197,11 @@ int main(int argc, char *argv[]) PstreamBuffers pBufs; labelList sendData; - if (Pstream::master()) + if (UPstream::master()) { sendData = identity(500); - for (const int proci : Pstream::subProcs()) + for (const int proci : UPstream::subProcs()) { UOPstream os(proci, pBufs); os << sendData; @@ -211,7 +211,7 @@ int main(int argc, char *argv[]) Info<< "call finishedSends()" << endl; pBufs.finishedScatters(); - if (!Pstream::master()) + if (UPstream::is_subrank()) { UIPstream is(UPstream::masterNo(), pBufs); is >> sendData; @@ -225,11 +225,11 @@ int main(int argc, char *argv[]) labelListList recvBufs(UPstream::nProcs()); labelList recvSizes; - if (Pstream::master()) + if (UPstream::master()) { - for (const int proci : Pstream::allProcs()) + for (const int proci : UPstream::allProcs()) { - if (proci != Pstream::myProcNo()) + if (proci != UPstream::myProcNo()) { sendBufs[proci] = identity(500); } @@ -253,11 +253,11 @@ int main(int argc, char *argv[]) Map recvBufs; Map