OPstreams.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) 2011 OpenFOAM Foundation
9  Copyright (C) 2022-2025 OpenCFD Ltd.
10  Copyright (C) 2026 Keysight Technologies
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "UOPstream.H"
31 #include "OPstream.H"
32 
33 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
34 
36 (
37  const UPstream::commsTypes commsType,
38  const int toProcNo,
39  DynamicList<char>& sendBuf,
40  const int tag,
41  const int comm,
42  const bool sendAtDestruct,
44 )
45 :
46  UOPstreamBase(commsType, toProcNo, sendBuf, tag, comm, sendAtDestruct, fmt)
47 {}
48 
49 
50 Foam::UOPstream::UOPstream(const int toProcNo, PstreamBuffers& buffers)
51 :
52  UOPstreamBase(toProcNo, buffers)
53 {}
54 
55 
57 (
58  DynamicList<char>& sendBuf,
60 )
61 :
62  UOPstreamBase(sendBuf, fmt)
63 {}
64 
65 
67 (
68  const UPstream::commsTypes commsType,
69  const int toProcNo,
70  const int bufferSize,
71  const int tag,
72  const int communicator,
74 )
75 :
76  Pstream(commsType, bufferSize),
77  UOPstream
78  (
79  commsType,
80  toProcNo,
81  Pstream::transferBuf_,
82  tag,
83  communicator,
84  true, // sendAtDestruct
85  fmt
86  )
87 {
88  // NOTE: nonBlocking with sendAtDestruct is a bad combination.
89  // The transfer buffer will be destroyed before the send completes!
90 
92  {
94  << "Constructed with non-blocking and send-at-destruct.\n"
95  << "This is an error - results in undefined behaviour!\n"
97  }
98 }
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
104 {
105  sendAtDestruct_ = false;
106  return bufferIPCsend();
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
111 
113 {
114  // Already flagged (nonBlocking + sendAtDestruct) as an error in
115  // the constructor...
116 
117  if (sendAtDestruct_)
118  {
119  if (!bufferIPCsend())
120  {
122  << "Failed sending outgoing message of size "
123  << sendBuf_.size() << " to processor " << toProcNo_
125  }
126  }
127 }
128 
129 
130 // ************************************************************************* //
commsTypes
Communications types.
Definition: UPstream.H:81
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:652
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:60
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:29
Inter-processor communications stream.
Definition: Pstream.H:57
errorManip< error > abort(error &err)
Definition: errorManip.H:139
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:2051
Output inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
Definition: UOPstream.H:491
virtual ~UOPstream()
Destructor, usually sends buffer on destruct.
Definition: OPstreams.C:105
Buffers for inter-processor communications streams (UOPstream, UIPstream).
bool sendAtDestruct_
Call bufferIPCsend on termination (in the destructor)
Definition: UOPstream.H:142
streamFormat
Data format (ascii | binary | coherent)
"nonBlocking" (immediate) : (MPI_Isend, MPI_Irecv)
Base class for output inter-processor communications stream (ie, parallel streams). Not to be used directly, thus contructors are protected.
Definition: UOPstream.H:56
bool send()
Send buffer contents now and not in destructor [advanced usage]. Returns true on success.
Definition: OPstreams.C:96