OPstream.H
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) 2011-2013 OpenFOAM Foundation
9  Copyright (C) 2021-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::OPstream
29 
30 Description
31  Output inter-processor communications stream.
32 
33 SourceFiles
34  OPstreams.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "Pstream.H"
39 
40 #ifndef Foam_OPstream_H
41 #define Foam_OPstream_H
42 
43 #include "UOPstream.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class OPstream Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class OPstream
55 :
56  public Pstream,
57  public UOPstream
58 {
59 public:
60 
61  // Constructors
62 
63  //- Construct for given process index to send to
64  //- and optional buffer size, write format
65  OPstream
66  (
68  const int toProcNo,
69  const label bufSize = 0,
70  const int tag = UPstream::msgType(),
71  const label comm = UPstream::worldComm,
73  );
74 
75 
76  // Static Functions
77 
78  //- Serialize a value and send (buffered/blocking or standard mode).
79  //- Uses \c operator<< for serialization
80  template<class Type>
81  static void send
82  (
83  const Type& value,
86  const int toProcNo,
87  const int tag = UPstream::msgType(),
88  const label comm = UPstream::worldComm,
90  )
91  {
92  OPstream os(commsType, toProcNo, 0, tag, comm, fmt);
93  os << value;
94  }
95 
96  //- Serialize a value and send (standard mode).
97  //- Uses \c operator<< for serialization
98  template<class Type>
99  static void send
100  (
101  const Type& value,
102  const int toProcNo,
103  const int tag = UPstream::msgType(),
104  const label comm = UPstream::worldComm,
106  )
107  {
109  (
110  value,
111  UPstream::commsTypes::scheduled, // ie, MPI_Send()
112  toProcNo,
113  tag,
114  comm,
115  fmt
116  );
117  }
118 };
119 
120 
121 /*---------------------------------------------------------------------------*\
122  Class OPBstream Declaration
123 \*---------------------------------------------------------------------------*/
124 
125 //- Output inter-processor communications stream
126 //- using MPI broadcast.
127 class OPBstream
128 :
129  public Pstream,
130  public UOPBstream
131 {
132 public:
133 
134  // Constructors
135 
136  //- Construct for broadcast root, optional buffer size, write format
137  OPBstream
138  (
139  const UPstream::commsTypes,
140  const int rootProcNo,
141  const label bufSize = 0,
142  const int tag = UPstream::msgType(),
143  const label comm = UPstream::worldComm,
145  );
146 
147  //- Construct for broadcast root and communicator,
148  //- with optional write format
149  OPBstream
150  (
151  const int rootProcNo,
152  const label comm,
154  );
155 
156  //- Construct with optional communicator and write format.
157  //- Uses UPstream::masterNo() root
158  explicit OPBstream
159  (
160  const label comm = UPstream::worldComm,
162  );
163 
164 
165  // Static Functions
166 
167  //- Serialize a value and broadcast (root == UPstream::masterNo()).
168  //- Uses \c operator<< for serialization
169  template<class Type>
170  static void send
171  (
172  const Type& value,
173  const label comm = UPstream::worldComm,
175  )
176  {
177  OPBstream os(comm, fmt);
178  os << value;
179  }
180 };
181 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
OPstream(const UPstream::commsTypes commsType, const int toProcNo, const label bufSize=0, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct for given process index to send to and optional buffer size, write format.
Definition: OPstreams.C:59
commsTypes
Communications types.
Definition: UPstream.H:77
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1252
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition: UPstream.H:421
static void send(const Type &value, const label comm=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Serialize a value and broadcast (root == UPstream::masterNo()). Uses operator<< for serialization...
Definition: OPstream.H:182
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
OPBstream(const UPstream::commsTypes, const int rootProcNo, const label bufSize=0, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct for broadcast root, optional buffer size, write format.
Definition: OPBstreams.C:52
Inter-processor communications stream.
Definition: Pstream.H:54
Output inter-processor communications stream using MPI broadcast - operating on external buffer...
Definition: UOPstream.H:588
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:1284
Output inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
Definition: UOPstream.H:394
OBJstream os(runTime.globalPath()/outputName)
Output inter-processor communications stream.
Definition: OPstream.H:49
Output inter-processor communications stream using MPI broadcast.
Definition: OPstream.H:130
streamFormat
Data format (ascii | binary)
bool send()
Send buffer contents now and not in destructor [advanced usage]. Returns true on success.
Definition: OPstreams.C:84
Namespace for OpenFOAM.