From c448ea2a1174246deeb9e17631fc3baec4c16228 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 25 Feb 2025 08:39:16 +0100 Subject: [PATCH] ENH: add simple handling for point-to-point barriers - provides an additional means of process synchronization --- .../test/parallel-barrier1/Make/files | 3 + .../test/parallel-barrier1/Make/options | 2 + .../Test-parallel-barrier1.cxx | 125 ++++++++++++++++++ src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H | 34 ++++- src/Pstream/dummy/UPstream.C | 26 +++- src/Pstream/mpi/PstreamGlobals.H | 2 +- src/Pstream/mpi/UPstream.C | 67 +++++++++- 7 files changed, 248 insertions(+), 11 deletions(-) create mode 100644 applications/test/parallel-barrier1/Make/files create mode 100644 applications/test/parallel-barrier1/Make/options create mode 100644 applications/test/parallel-barrier1/Test-parallel-barrier1.cxx diff --git a/applications/test/parallel-barrier1/Make/files b/applications/test/parallel-barrier1/Make/files new file mode 100644 index 0000000000..9256068d0b --- /dev/null +++ b/applications/test/parallel-barrier1/Make/files @@ -0,0 +1,3 @@ +Test-parallel-barrier1.cxx + +EXE = $(FOAM_USER_APPBIN)/Test-parallel-barrier1 diff --git a/applications/test/parallel-barrier1/Make/options b/applications/test/parallel-barrier1/Make/options new file mode 100644 index 0000000000..18e6fe47af --- /dev/null +++ b/applications/test/parallel-barrier1/Make/options @@ -0,0 +1,2 @@ +/* EXE_INC = */ +/* EXE_LIBS = */ diff --git a/applications/test/parallel-barrier1/Test-parallel-barrier1.cxx b/applications/test/parallel-barrier1/Test-parallel-barrier1.cxx new file mode 100644 index 0000000000..586539752d --- /dev/null +++ b/applications/test/parallel-barrier1/Test-parallel-barrier1.cxx @@ -0,0 +1,125 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2025 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-barrier1 + +Description + Simple test of local barriers communication + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "clockTime.H" +#include "IPstream.H" +#include "OPstream.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char *argv[]) +{ + argList::noCheckProcessorDirectories(); + argList::addVerboseOption(); + argList::addOption("delay", "sec", "Seconds to sleep (default 2)"); + + #include "setRootCase.H" + + if (!UPstream::parRun()) + { + Info<< "###############" << nl + << "Not running in parallel. Stopping now" << nl + << "###############" << endl; + return 1; + } + + const auto delay = args.getOrDefault