UPstreamBroadcast.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "UPstream.H"
29#include "PstreamGlobals.H"
30#include "profilingPstream.H"
31
32#include <mpi.h>
33
34// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35
37(
38 char* buf,
39 const std::streamsize bufSize,
40 const label comm,
41 const int rootProcNo
42)
43{
44 if (!UPstream::parRun() || UPstream::nProcs(comm) < 2)
45 {
46 // Nothing to do - ignore
47 return true;
48 }
49
50 //Needed? PstreamGlobals::checkCommunicator(comm, rootProcNo);
51
52 if (debug)
53 {
54 Pout<< "UPstream::broadcast : root:" << rootProcNo
55 << " comm:" << comm
56 << " size:" << label(bufSize)
57 << Foam::endl;
58 }
59 if (UPstream::warnComm != -1 && comm != UPstream::warnComm)
60 {
61 Pout<< "UPstream::broadcast : root:" << rootProcNo
62 << " comm:" << comm
63 << " size:" << label(bufSize)
64 << " warnComm:" << UPstream::warnComm
65 << Foam::endl;
67 }
68
70
71 bool failed = MPI_Bcast
72 (
73 buf,
74 bufSize,
75 MPI_BYTE,
76 rootProcNo,
78 );
79
81
82 return !failed;
83}
84
85
86// ************************************************************************* //
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:296
static bool broadcast(char *buf, const std::streamsize bufSize, const label communicator=worldComm, const int rootProcNo=masterNo())
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
static void printStack(Ostream &os)
Helper function to print a stack.
static void addBroadcastTime()
Add time increment to broadcastTime.
static void beginTiming()
Update timer prior to measurement.
DynamicList< MPI_Comm > MPICommunicators_
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.