IPstreams.C
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) 2022-2025 OpenCFD Ltd.
9  Copyright (C) 2026 Keysight Technologies
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 \*---------------------------------------------------------------------------*/
28 
29 #include "UIPstream.H"
30 #include "IPstream.H"
31 #include "IOstreams.H"
32 
33 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
34 
36 (
37  const UPstream::commsTypes commsType,
38  const int fromProcNo,
39  DynamicList<char>& receiveBuf,
40  label& receiveBufPosition,
41  const int tag,
42  const int communicator,
43  const bool clearAtEnd,
45 )
46 :
48  (
49  commsType,
50  fromProcNo,
51  receiveBuf,
52  receiveBufPosition,
53  tag,
55  clearAtEnd,
56  fmt
57  )
58 {
60  {
61  // Message is already received into buffer
62  }
63  else
64  {
65  bufferIPCrecv();
66  }
67 }
68 
69 
70 Foam::UIPstream::UIPstream(const int fromProcNo, PstreamBuffers& buffers)
71 :
72  UIPstreamBase(fromProcNo, buffers)
73 {
75  {
76  // Message is already received into buffer
78 
79  if (debug)
80  {
81  Perr<< "UIPstream::UIPstream PstreamBuffers :"
82  << " fromProcNo:" << fromProcNo_
83  << " tag:" << tag_ << " comm:" << comm_
84  << " receive buffer size:" << messageSize_
85  << Foam::endl;
86  }
87  }
88  else
89  {
90  bufferIPCrecv();
91  }
92 }
93 
94 
96 (
97  const DynamicList<char>& recvBuf,
99 )
100 :
101  UIPstreamBase(recvBuf, fmt)
102 {}
103 
104 
106 (
107  const UPstream::commsTypes commsType,
108  const int fromProcNo,
109  const int bufferSize,
110  const int tag,
111  const int communicator,
113 )
114 :
115  Pstream(commsType, bufferSize),
116  UIPstream
117  (
118  commsType,
119  fromProcNo,
120  Pstream::transferBuf_,
121  UIPstreamBase::storedRecvBufPos_, // Internal only
122  tag,
123  communicator,
124  false, // Do not clear Pstream::transferBuf_ if at end
125  fmt
126  )
127 {}
128 
129 
130 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
131 
133 {
134  // Grab contents
135  DynamicList<char> contents(std::move(Pstream::transferBuf_));
136 
137  // Reset input position parameters and sizes
142 
143  return contents;
144 }
145 
146 
147 // ************************************************************************* //
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:119
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:99
commsTypes
Communications types.
Definition: UPstream.H:81
Base class for input inter-processor communications stream (ie, parallel streams). Not to be used directly, thus contructors are protected.
Definition: UIPstream.H:56
int fromProcNo_
Source rank for the data.
Definition: UIPstream.H:100
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:518
label & recvBufPos_
Reference to the receive position in buffer data.
Definition: UIPstream.H:136
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Input inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
Definition: UIPstream.H:365
label messageSize_
The message size, read on bufferIPCrecv or set directly.
Definition: UIPstream.H:115
label storedRecvBufPos_
Receive position in buffer data. If there is no external location for recvBufPos_.
Definition: UIPstream.H:121
DynamicList< char > release()
Release contents of the input buffer and reset the stream.
Definition: IPstreams.C:125
Inter-processor communications stream.
Definition: Pstream.H:57
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, optional communication characteristics and IO format.
Definition: IPstreams.C:29
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:2051
int debug
Static debugging option.
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
Definition: UPstream.H:2667
decomposeUsingBbs false
Use bounding boxes (default) or unique decomposition of triangles (i.e. do not duplicate triangles) ...
DynamicList< char > & recvBuf_
Reference to the receive buffer data.
Definition: UIPstream.H:131
virtual void rewind() override
Rewind the receive stream position so that it may be read again.
const int tag_
Message tag for communication.
Definition: UIPstream.H:105
streamFormat
Data format (ascii | binary | coherent)
"nonBlocking" (immediate) : (MPI_Isend, MPI_Irecv)
DynamicList< char > transferBuf_
Allocated transfer buffer (can be used for send or receive)
Definition: Pstream.H:68
const int comm_
The communicator index.
Definition: UIPstream.H:110