From ffeef76d8f342df17f3151e4fc88f0992240cc6c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 29 Nov 2022 11:37:29 +0100 Subject: [PATCH] ENH: cleaner separation of global and local world naming - UPstream::globalComm constant always refers to MPI_COMM_WORLD but UPstream::worldComm could be MPI_COMM_WORLD (single world) or a dedicated local communicator (for multi-world). - provide a Pstream wrapped version of MPI_COMM_SELF, references as UPstream::selfComm - UPstream::isUserComm(label) test for additional user-defined communicators --- applications/test/parallel-comm0/Make/files | 3 + .../Make/options | 0 .../test/parallel-comm0/Test-parallel-comm0.C | 161 +++++++++++++++ applications/test/parallel-comm1/Make/files | 3 + applications/test/parallel-comm1/Make/options | 2 + .../Test-parallel-comm1.C} | 0 .../test/parallel-communicators/Make/files | 3 - .../Test-parallel-external-init.C | 102 ++++++++- src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C | 176 ++++++++++------ src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H | 122 ++++++----- .../IOstreams/Pstreams/UPstreamCommsStruct.C | 21 +- src/Pstream/mpi/PstreamGlobals.H | 6 +- src/Pstream/mpi/UPstream.C | 193 ++++++++++-------- .../multiWorld/multiWorldConnectionsObject.C | 12 +- 14 files changed, 575 insertions(+), 229 deletions(-) create mode 100644 applications/test/parallel-comm0/Make/files rename applications/test/{parallel-communicators => parallel-comm0}/Make/options (100%) create mode 100644 applications/test/parallel-comm0/Test-parallel-comm0.C create mode 100644 applications/test/parallel-comm1/Make/files create mode 100644 applications/test/parallel-comm1/Make/options rename applications/test/{parallel-communicators/Test-parallel-communicators.C => parallel-comm1/Test-parallel-comm1.C} (100%) delete mode 100644 applications/test/parallel-communicators/Make/files diff --git a/applications/test/parallel-comm0/Make/files b/applications/test/parallel-comm0/Make/files new file mode 100644 index 0000000000..cdf4e68ab1 --- /dev/null +++ b/applications/test/parallel-comm0/Make/files @@ -0,0 +1,3 @@ +Test-parallel-comm0.C + +EXE = $(FOAM_USER_APPBIN)/Test-parallel-comm0 diff --git a/applications/test/parallel-communicators/Make/options b/applications/test/parallel-comm0/Make/options similarity index 100% rename from applications/test/parallel-communicators/Make/options rename to applications/test/parallel-comm0/Make/options diff --git a/applications/test/parallel-comm0/Test-parallel-comm0.C b/applications/test/parallel-comm0/Test-parallel-comm0.C new file mode 100644 index 0000000000..dc6fdb064f --- /dev/null +++ b/applications/test/parallel-comm0/Test-parallel-comm0.C @@ -0,0 +1,161 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Application + Test-parallel-comm0 + +Description + Very basic checks on standard communicators + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "Time.H" +#include "IPstream.H" +#include "OPstream.H" +#include "Pair.H" +#include "Tuple2.H" +#include "IOstreams.H" +#include "PstreamReduceOps.H" + +using namespace Foam; + + +void printInfo(const label comm) +{ + Info<< "comm:" << comm + << " nprocs:" << UPstream::nProcs(comm) + << " all:" << UPstream::allProcs(comm) + << " sub:" << UPstream::subProcs(comm) << nl; + + + if (UPstream::selfComm == comm) + { + Pout<< "self all:" << UPstream::allProcs(comm) + << " sub:" << UPstream::subProcs(comm) << nl; + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char *argv[]) +{ + argList::noBanner(); + argList::noCheckProcessorDirectories(); + argList::addBoolOption("verbose", "Set debug level"); + + // Capture manually. We need values before proper startup + int nVerbose = 0; + for (int argi = 1; argi < argc; ++argi) + { + if (strcmp(argv[argi], "-verbose") == 0) + { + ++nVerbose; + } + } + + UPstream::debug = nVerbose; + + + #include "setRootCase.H" + + Info<< nl + << "nProcs = " << UPstream::nProcs() + << " with " << UPstream::nComms() << " predefined comm(s)" << nl; + + Info<< "worldComm : "; + printInfo(UPstream::worldComm); + + Info<< "selfComm : "; + printInfo(UPstream::selfComm); + + Info<< nl; + + // Reductions (using MPI intrinsics) + { + label val = Pstream::myProcNo(UPstream::worldComm); + + label worldVal = returnReduce + ( + val, + sumOp