Loading...
Searching...
No Matches
UIPBstreamRead.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-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "UIPstream.H"
29#include "IOstreams.H"
30#include "PstreamGlobals.H"
31
32// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33
34void Foam::UIPBstream::bufferIPCrecv()
35{
36 // Uses double broadcast. Symmetric with UOPBstream::bufferIPCsend()
37 // 1. for the data size
38 // 2. for the data itself
39
40 // Broadcast #1 - data size
41 // Same data type must be used in UOPBstream::bufferIPCsend()
42
43 int64_t count(0);
45 {
47 << "Broadcast failure receiving buffer size" << nl
48 << " comm:" << comm_ << nl
50 }
51
52 // This is not actually possible - sender uses List::size()
53 //
54 // if (FOAM_UNLIKELY(count > int64_t(UList<char>::max_size())))
55 // {
56 // FatalErrorInFunction
57 // << "Broadcast list size larger than UList<char>::max_size()"
58 // << Foam::abort(FatalError);
59 // }
60
61 if (FOAM_UNLIKELY(UPstream::debug))
62 {
63 Perr<< "UIPBstream IPC read buffer :"
64 << " comm:" << comm_
65 << " probed size:" << label(count)
66 << " wanted size:" << recvBuf_.capacity()
67 << Foam::endl;
68 }
69
70
71 // Set buffer size, avoiding any copying and resize doubling etc.
72 recvBuf_.clear();
73 if (recvBuf_.capacity() < label(count))
74 {
75 recvBuf_.setCapacity_nocopy(label(count));
76 }
77 recvBuf_.resize_nocopy(label(count));
78
79 // This is the only real information we can trust
80 messageSize_ = label(count);
81
82
83 // Broadcast #2 - data content
84 // - skip if there is no data to receive
85 if
86 (
87 (count > 0) // ie, not empty
89 (
90 recvBuf_.data(),
91 recvBuf_.size(), // same as count
93 comm_
94 )
95 )
96 {
98 << "Broadcast failure receiving buffer data:"
99 << recvBuf_.size() << " comm:" << comm_ << nl
101 }
102
103 if (recvBuf_.empty())
104 {
105 setEof();
106 }
107}
108
109
110// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void setEof() noexcept
Set stream state as reached 'eof'.
Definition IOstream.H:472
const int comm_
The communicator index.
Definition UIPstream.H:109
label messageSize_
The message size, read on bufferIPCrecv or set directly.
Definition UIPstream.H:114
DynamicList< char > & recvBuf_
Reference to the receive buffer data.
Definition UIPstream.H:130
static bool mpi_broadcast(void *buf, std::streamsize count, const UPstream::dataTypes dataTypeId, const int communicator, const int root=0)
Broadcast buffer contents to all ranks (default: from rank=0). The sizes must match on all processes.
@ type_byte
byte, char, unsigned char, ...
Definition UPstream.H:113
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition BitOps.H:73
bool broadcast_int64(int64_t &value, int comm, int root=0)
Broadcast a single int64 value.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
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...
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define FOAM_UNLIKELY(cond)
Definition stdFoam.H:64