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 -------------------------------------------------------------------------------
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::IPstream
29 
30 Description
31  Input inter-processor communications stream.
32 
33 SourceFiles
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 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class IPstream Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class IPstream
55 :
56  public Pstream,
57  public UIPstream
58 {
59 public:
60 
61  // Constructors
62 
63  //- Construct given process index to read from
64  IPstream
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.
109 class IPBstream
110 :
111  public Pstream,
112  public UIPBstream
113 {
114 public:
115 
116  // Constructors
117 
118  //- Construct with optional communicator and read format.
119  //- Uses UPstream::masterNo() root
120  explicit IPBstream
121  (
122  const int communicator = UPstream::worldComm,
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  )
138  {
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  {
156  IPBstream is(communicator);
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 // ************************************************************************* //
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
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
commsTypes
Communications types.
Definition: UPstream.H:77
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 int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1787
const int tag
Definition: Pstream.H:871
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition: UPstream.H:987
Input inter-processor communications stream.
Definition: IPstream.H:49
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
Input inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
Definition: UIPstream.H:295
Input inter-processor communications stream using MPI broadcast - operating on external buffer...
Definition: UIPstream.H:466
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
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
Inter-processor communications stream.
Definition: Pstream.H:53
void inputLoop(IS &is, Type &arg1, Args &&... args)
Input looping. Read into first parameter and recurse.
Definition: IOstream.H:635
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:1819
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
Definition: UPstream.H:2237
Input inter-processor communications stream using MPI broadcast.
Definition: IPstream.H:110
streamFormat
Data format (ascii | binary)
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
Namespace for OpenFOAM.