Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::OPstream
29
30Description
31 Output inter-processor communications stream.
32
33SourceFiles
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
47namespace Foam
48{
50/*---------------------------------------------------------------------------*\
51 Class OPstream Declaration
52\*---------------------------------------------------------------------------*/
53
54class OPstream
55:
56 public Pstream,
57 public UOPstream
58{
59public:
60
61 // Constructors
62
63 //- Construct for given process index to send to
65 (
67 const int toProcNo,
68 const int bufferSize = 0,
69 const int tag = UPstream::msgType(),
72 );
73
74
75 // Static Functions
76
77 //- Serialize a value and send (buffered/blocking or standard mode).
78 //- Uses \c operator<< for serialization
79 template<class Type>
80 static void send
81 (
82 const Type& value,
85 const int toProcNo,
86 const int tag = UPstream::msgType(),
89 )
90 {
91 OPstream os(commsType, toProcNo, 0, tag, communicator, fmt);
92 os << value;
93 }
94
95 //- Serialize a value and send (standard mode).
96 //- Uses \c operator<< for serialization
97 template<class Type>
98 static void send
99 (
100 const Type& value,
101 const int toProcNo,
102 const int tag = UPstream::msgType(),
105 )
106 {
108 (
109 value,
110 UPstream::commsTypes::scheduled, // ie, MPI_Send()
111 toProcNo,
112 tag,
114 fmt
115 );
116 }
117};
118
119
120/*---------------------------------------------------------------------------*\
121 Class OPBstream Declaration
122\*---------------------------------------------------------------------------*/
123
124//- Output inter-processor communications stream
125//- using MPI broadcast.
126class OPBstream
127:
128 public Pstream,
130{
131public:
132
133 // Constructors
134
135 //- Construct with optional communicator and write format.
136 explicit OPBstream
137 (
140 );
141
142
143 // Static Functions
144
145 //- Use all send methods from base
146 using UOPBstream::send;
147
148 //- Serialize a value and broadcast (root == UPstream::masterNo()).
149 //- Uses \c operator<< for serialization
150 template<class Type>
151 static void send
152 (
153 const Type& value,
155 )
156 {
158 {
159 os << value;
161 }
162
163 //- Serialize multiple items and broadcast the buffer
164 //- Uses \c operator<< for serialization
165 template<class Type, class... Args>
166 static void sends
167 (
168 const int communicator,
169 Type& value,
170 Args&&... values
171 )
172 {
173 OPBstream os(communicator);
174 {
175 Detail::outputLoop(os, value, std::forward<Args>(values)...);
176 // Depending on compiler support:
177 // Pack via fold expression
178 // (((os << value) << std::forward<Args>(values)), ...);
179 }
180 }
181};
182
183
184// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185
186} // End namespace Foam
187
188// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189
190#endif
191
192// ************************************************************************* //
streamFormat
Data format (ascii | binary | coherent).
OPBstream(const int communicator=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct with optional communicator and write format.
Definition OPBstreams.C:49
static void send(const Type &value, const int communicator=UPstream::worldComm)
Serialize a value and broadcast (root == UPstream::masterNo()). Uses operator<< for serialization.
Definition OPstream.H:161
static void sends(const int communicator, Type &value, Args &&... values)
Serialize multiple items and broadcast the buffer Uses operator<< for serialization.
Definition OPstream.H:178
static void send(const Type &value, const int toProcNo, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Serialize a value and send (standard mode). Uses operator<< for serialization.
Definition OPstream.H:100
OPstream(const UPstream::commsTypes commsType, const int toProcNo, const int bufferSize=0, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct for given process index to send to.
Definition OPstreams.C:59
static void send(const Type &value, const UPstream::commsTypes commsType, const int toProcNo, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Serialize a value and send (buffered/blocking or standard mode). Uses operator<< for serialization.
Definition OPstream.H:80
Pstream(const UPstream::commsTypes commsType) noexcept
Construct for communication type with empty buffer.
Definition Pstream.H:83
const int tag
Definition Pstream.H:874
UOPBstream(DynamicList< char > &sendBuf, const int communicator=UPstream::worldComm, const bool sendAtDestruct=true, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct with attached send buffer, optional communication characteristics and IO format.
Definition OPBstreams.C:28
static void send(Foam::zero, int communicator, int root=0)
Broadcast a zero value (buffer) size that can be matched by the UIPBstream constructor.
UOPstream(const UPstream::commsTypes commsType, const int toProcNo, DynamicList< char > &sendBuf, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, const bool sendAtDestruct=true, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct given process index to write to using the given attached send buffer, optional communicatio...
Definition OPstreams.C:28
bool send()
Send buffer contents now and not in destructor [advanced usage]. Returns true on success.
Definition OPstreams.C:84
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
Definition UPstream.H:2546
commsTypes
Communications types.
Definition UPstream.H:81
@ scheduled
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
Definition UPstream.H:83
static int & msgType() noexcept
Message tag of standard messages.
Definition UPstream.H:1926
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition UPstream.H:1958
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition UPstream.H:1069
OBJstream os(runTime.globalPath()/outputName)
void outputLoop(OS &os, const Type &arg1, Args &&... args)
Output looping. Write first parameter and recurse.
Definition IOstream.H:667
Namespace for OpenFOAM.