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-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::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  //- and optional buffer size, read format
65  IPstream
66  (
68  const int fromProcNo,
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  //- Receive and deserialize a value.
79  //- Uses \c operator>> for de-serialization
80  template<class Type>
81  static void recv
82  (
83  Type& value,
84  const int fromProcNo,
85  const int tag = UPstream::msgType(),
86  const label comm = UPstream::worldComm,
88  )
89  {
90  IPstream is
91  (
92  UPstream::commsTypes::scheduled, // ie, MPI_Recv()
93  fromProcNo,
94  0, // bufSize
95  tag,
96  comm,
97  fmt
98  );
99  is >> value;
100  }
101 };
102 
103 
104 /*---------------------------------------------------------------------------*\
105  Class IPBstream Declaration
106 \*---------------------------------------------------------------------------*/
107 
108 //- Input inter-processor communications stream
109 //- using MPI broadcast.
110 class IPBstream
111 :
112  public Pstream,
113  public UIPBstream
114 {
115 public:
116 
117  // Constructors
118 
119  //- Construct for broadcast root, optional buffer size, read format
120  IPBstream
121  (
122  const UPstream::commsTypes,
123  const int rootProcNo,
124  const label bufSize = 0,
125  const int tag = UPstream::msgType(),
126  const label comm = UPstream::worldComm,
128  );
129 
130  //- Construct for broadcast root and communicator,
131  //- with optional read format
132  IPBstream
133  (
134  const int rootProcNo,
135  const label comm,
137  );
138 
139  //- Construct with optional communicator and read format.
140  //- Uses UPstream::masterNo() root
141  explicit IPBstream
142  (
143  const label comm = UPstream::worldComm,
145  );
146 
147 
148  // Static Functions
149 
150  //- Receive (from broadcast, root == UPstream::masterNo())
151  //- and deserialize a value.
152  //- Uses \c operator>> for de-serialization
153  template<class Type>
154  static void recv
155  (
156  Type& value,
157  const label comm = UPstream::worldComm,
159  )
160  {
161  IPBstream is(comm, fmt);
162  is >> value;
163  }
164 };
165 
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 } // End namespace Foam
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 #endif
174 
175 // ************************************************************************* //
IPBstream(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, read format.
Definition: IPBstreams.C:56
IPstream(const UPstream::commsTypes commsType, const int fromProcNo, const label bufSize=0, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct given process index to read from and optional buffer size, read format. ...
Definition: IPstreams.C:98
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
Input inter-processor communications stream.
Definition: IPstream.H:49
Input inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
Definition: UIPstream.H:289
Input inter-processor communications stream using MPI broadcast - operating on external buffer...
Definition: UIPstream.H:530
static void recv(Type &value, const int fromProcNo, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Receive and deserialize a value. Uses operator>> for de-serialization.
Definition: IPstream.H:81
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
Inter-processor communications stream.
Definition: Pstream.H:54
static void recv(Type &value, const label comm=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Receive (from broadcast, root == UPstream::masterNo()) and deserialize a value. Uses operator>> for d...
Definition: IPstream.H:164
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:1284
Input inter-processor communications stream using MPI broadcast.
Definition: IPstream.H:111
streamFormat
Data format (ascii | binary)
Namespace for OpenFOAM.