Loading...
Searching...
No Matches
IPstream.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::IPstream
29
30Description
31 Input inter-processor communications stream.
32
33SourceFiles
34 IPstreams.C
35
36\*---------------------------------------------------------------------------*/
37
38#include "Pstream.H"
39
40#ifndef Foam_IPstream_H
41#define Foam_IPstream_H
42
43#include "UIPstream.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
50/*---------------------------------------------------------------------------*\
51 Class IPstream Declaration
52\*---------------------------------------------------------------------------*/
53
54class IPstream
55:
56 public Pstream,
57 public UIPstream
58{
59public:
60
61 // Constructors
62
63 //- Construct given process index to read from
65 (
67 const int fromProcNo,
68 const int bufferSize = 0,
69 const int tag = UPstream::msgType(),
72 );
73
74
75 // Static Functions
76
77 //- Receive and deserialize a value.
78 //- Uses \c operator>> for de-serialization
79 template<class Type>
80 static void recv
81 (
82 Type& value,
83 const int fromProcNo,
84 const int tag = UPstream::msgType(),
87 )
88 {
89 IPstream is
90 (
91 UPstream::commsTypes::scheduled, // ie, MPI_Recv()
92 fromProcNo,
93 0, // bufferSize
94 tag,
96 fmt
97 );
98 is >> value;
99 }
100};
101
102
103/*---------------------------------------------------------------------------*\
104 Class IPBstream Declaration
105\*---------------------------------------------------------------------------*/
106
107//- Input inter-processor communications stream
108//- using MPI broadcast.
109class IPBstream
111 public Pstream,
112 public UIPBstream
113{
114public:
115
116 // Constructors
117
118 //- Construct with optional communicator and read format.
119 //- Uses UPstream::masterNo() root
120 explicit IPBstream
121 (
124 );
125
126
127 // Static Functions
128
129 //- Receive (from broadcast, root == UPstream::masterNo())
130 //- and deserialize a value.
131 //- Uses \c operator>> for de-serialization
132 template<class Type>
133 static void recv
134 (
135 Type& value,
137 )
140 {
141 is >> value;
142 }
143 }
144
145 //- Receive (from broadcast) a buffer and deserialize
146 //- multiple items.
147 //- Uses \c operator>> for de-serialization
148 template<class Type, class... Args>
149 static void recvs
150 (
151 const int communicator,
152 Type& value,
153 Args&&... values
154 )
155 {
157 {
158 Detail::inputLoop(is, value, std::forward<Args>(values)...);
159 // Depending on compiler support:
160 // Unpack via fold expression
161 // (((is >> value) >> std::forward<Args>(values)), ...);
162 }
163 }
164};
165
166
167// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168
169} // End namespace Foam
170
171// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172
173#endif
174
175// ************************************************************************* //
streamFormat
Data format (ascii | binary | coherent).
static void recv(Type &value, const int communicator=UPstream::worldComm)
Receive (from broadcast, root == UPstream::masterNo()) and deserialize a value. Uses operator>> for d...
Definition IPstream.H:139
IPBstream(const int communicator=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct with optional communicator and read format. Uses UPstream::masterNo() root.
Definition IPBstreams.C:53
static void recvs(const int communicator, Type &value, Args &&... values)
Receive (from broadcast) a buffer and deserialize multiple items. Uses operator>> for de-serializatio...
Definition IPstream.H:157
static void recv(Type &value, const int fromProcNo, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Receive and deserialize a value. Uses operator>> for de-serialization.
Definition IPstream.H:80
IPstream(const UPstream::commsTypes commsType, const int fromProcNo, const int bufferSize=0, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct given process index to read from.
Definition IPstreams.C:98
Pstream(const UPstream::commsTypes commsType) noexcept
Construct for communication type with empty buffer.
Definition Pstream.H:83
const int tag
Definition Pstream.H:874
UIPBstream(DynamicList< char > &receiveBuf, label &receiveBufPosition, const int communicator=UPstream::worldComm, const bool clearAtEnd=false, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct using the given attached receive buffer,.
Definition IPBstreams.C:28
UIPstream(const UPstream::commsTypes commsType, const int fromProcNo, DynamicList< char > &receiveBuf, label &receiveBufPosition, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, const bool clearAtEnd=false, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct given process index to read from using the given attached receive buffer,...
Definition IPstreams.C:28
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
void inputLoop(IS &is, Type &arg1, Args &&... args)
Input looping. Read into first parameter and recurse.
Definition IOstream.H:654
Namespace for OpenFOAM.