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-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
35 (
36  char* buf,
37  const std::streamsize bufSize,
38  const label comm,
39  const int rootProcNo
40 )
41 {
42  if (!UPstream::is_parallel(comm))
43  {
44  // Nothing to do - ignore
45  return true;
46  }
47 
48  //Needed? PstreamGlobals::checkCommunicator(comm, rootProcNo);
49 
50  if (UPstream::debug)
51  {
52  Pout<< "UPstream::broadcast : root:" << rootProcNo
53  << " comm:" << comm
54  << " size:" << label(bufSize)
55  << Foam::endl;
56  }
57  if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
58  {
59  Pout<< "UPstream::broadcast : root:" << rootProcNo
60  << " comm:" << comm
61  << " size:" << label(bufSize)
62  << " warnComm:" << UPstream::warnComm
63  << Foam::endl;
65  }
66 
68 
69  const int returnCode = MPI_Bcast
70  (
71  buf,
72  bufSize,
73  MPI_BYTE,
74  rootProcNo,
76  );
77 
79 
80  return (returnCode == MPI_SUCCESS);
81 }
82 
83 
84 // ************************************************************************* //
DynamicList< MPI_Comm > MPICommunicators_
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
static bool is_parallel(const label communicator=worldComm)
True if parallel algorithm or exchange is required.
Definition: UPstream.H:1066
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:416
static void beginTiming()
Update timer prior to measurement.
int debug
Static debugging option.
static void addBroadcastTime()
Add time increment to broadcast time.
static bool broadcast(char *buf, const std::streamsize bufSize, const label communicator, const int rootProcNo=masterNo())
Broadcast buffer contents to all processes in given communicator. The sizes must match on all process...
static void printStack(Ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.