Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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
27\*---------------------------------------------------------------------------*/
28
29#include "UOPstream.H"
30#include "OPstream.H"
31
32// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
33
35(
37 const int toProcNo,
38 DynamicList<char>& sendBuf,
39 const int tag,
40 const int comm,
41 const bool sendAtDestruct,
43)
44:
45 UOPstreamBase(commsType, toProcNo, sendBuf, tag, comm, sendAtDestruct, fmt)
46{}
47
49Foam::UOPstream::UOPstream(const int toProcNo, PstreamBuffers& buffers)
50:
51 UOPstreamBase(toProcNo, buffers)
52{}
53
54
56(
57 DynamicList<char>& sendBuf,
59)
60:
61 UOPstreamBase(sendBuf, fmt)
62{}
63
64
66(
67 const UPstream::commsTypes commsType,
68 const int toProcNo,
69 const int bufferSize,
70 const int tag,
71 const int communicator,
73)
74:
75 Pstream(commsType, bufferSize),
77 (
78 commsType,
79 toProcNo,
80 Pstream::transferBuf_,
81 tag,
82 communicator,
83 true, // sendAtDestruct
84 fmt
85 )
86{}
87
88
89// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90
92{
94 return bufferIPCsend();
95}
96
97
98// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
99
101{
102 if (sendAtDestruct_)
103 {
104 // Note: sendAtDestruct_ and nonBlocking is a questionable combination
105 // since the transfer buffer will be destroyed before
106 // the non-blocking send completes!
107 //
108 // Could flag as an error, but not actually used anywhere.
109
110 if (!bufferIPCsend())
111 {
113 << "Failed sending outgoing message of size "
114 << sendBuf_.size() << " to processor " << toProcNo_
116 }
117 }
118}
119
120
121// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
streamFormat
Data format (ascii | binary | coherent).
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:59
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Inter-processor communications stream.
Definition Pstream.H:59
DynamicList< char > transferBuf_
Allocated transfer buffer (can be used for send or receive).
Definition Pstream.H:67
Pstream(const UPstream::commsTypes commsType) noexcept
Construct for communication type with empty buffer.
Definition Pstream.H:83
const int tag
Definition Pstream.H:874
Base class for output inter-processor communications stream (ie, parallel streams)....
Definition UOPstream.H:59
DynamicList< char > & sendBuf_
Reference to the send buffer data.
Definition UOPstream.H:128
const int toProcNo_
Destination rank for the data.
Definition UOPstream.H:108
bool sendAtDestruct_
Call bufferIPCsend on termination (in the destructor).
Definition UOPstream.H:123
UOPstreamBase(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...
Output inter-processor communications stream using MPI send/recv etc. - operating on external buffer.
Definition UOPstream.H:408
virtual ~UOPstream()
Destructor, usually sends buffer on destruct.
Definition OPstreams.C:93
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:28
bool send()
Send buffer contents now and not in destructor [advanced usage]. Returns true on success.
Definition OPstreams.C:84
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
Definition UPstream.H:2546
commsTypes
Communications types.
Definition UPstream.H:81
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition UPstream.H:1958
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...