From 512ec01328fe9b23afdb676db5f2367831d7c3ad Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 6 Feb 2025 18:45:39 +0100 Subject: [PATCH] ENH: rationalize some globalIndex gather routines - replace gatherValues() with listGatherValues(), which returns the gathered values instead of passing by argument. This makes it less fragile and more convenient. Naming as per Pstream::listGatherValues(), but still retaining the original parameter order. - rename inplace 'gather' variant as 'gatherInplace' for clarity. - changed signature of lowest-level globalIndex::gather routines from List to UList for the output and removed any resizing. This means that the caller is responsible for ensuring that the receiving field is adequately sized (on master). This change allows potential reuse of 'work' arrays etc. The only code change for using this low-level gather was in GAMGAgglomeration. --- .../GAMGAgglomerateLduAddressing.C | 30 +- .../GAMGAgglomerationTemplates.C | 22 +- .../parallel/globalIndex/globalIndex.H | 134 +++--- .../globalIndex/globalIndexTemplates.C | 426 +++++++++++------- .../field/AMIWeights/AMIWeights.C | 5 +- .../distributedTriSurfaceMesh.C | 25 +- .../noiseModels/surfaceNoise/surfaceNoise.C | 12 +- 7 files changed, 364 insertions(+), 290 deletions(-) diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerateLduAddressing.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerateLduAddressing.C index bdbc65d281..46aeb381ff 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerateLduAddressing.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerateLduAddressing.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -559,29 +559,28 @@ void Foam::GAMGAgglomeration::procAgglomerateRestrictAddressing const label levelIndex ) { + const bool master = + ( + UPstream::myProcNo(comm) == (procIDs.empty() ? 0 : procIDs[0]) + ); + // Collect number of cells - labelList nFineCells; - globalIndex::gatherValues + labelList nFineCells = globalIndex::listGatherValues ( comm, procIDs, restrictAddressing_[levelIndex].size(), - nFineCells, - UPstream::msgType(), UPstream::commsTypes::scheduled ); labelList fineOffsets(globalIndex::calcOffsets(nFineCells)); // Combine and renumber nCoarseCells - labelList nCoarseCells; - globalIndex::gatherValues + labelList nCoarseCells = globalIndex::listGatherValues ( comm, procIDs, nCells_[levelIndex], - nCoarseCells, - UPstream::msgType(), UPstream::commsTypes::scheduled ); @@ -589,6 +588,11 @@ void Foam::GAMGAgglomeration::procAgglomerateRestrictAddressing // (cell)restrictAddressing labelList procRestrictAddressing; + if (master) + { + // pre-size on master + procRestrictAddressing.resize(fineOffsets.back()); + } globalIndex::gather ( fineOffsets, @@ -596,15 +600,13 @@ void Foam::GAMGAgglomeration::procAgglomerateRestrictAddressing procIDs, restrictAddressing_[levelIndex], procRestrictAddressing, - UPstream::msgType(), - Pstream::commsTypes::nonBlocking //Pstream::commsTypes::scheduled + UPstream::commsTypes::nonBlocking ); - - if (Pstream::myProcNo(comm) == procIDs[0]) + if (master) { - nCells_[levelIndex] = coarseOffsets.last(); // ie, totalSize() + nCells_[levelIndex] = coarseOffsets.back(); // ie, totalSize() // Renumber consecutively for (label proci = 1; proci < procIDs.size(); ++proci) diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerationTemplates.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerationTemplates.C index 8d13291110..f236bde8a5 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerationTemplates.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerationTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2023 OpenCFD Ltd. + Copyright (C) 2023-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -78,17 +78,17 @@ void Foam::GAMGAgglomeration::restrictField const label coarseComm = UPstream::parent(procCommunicator_[coarseLevelIndex]); - const List