Loading...
Searching...
No Matches
UOPBstreamWrite.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 "UOPstream.H"
29#include "PstreamGlobals.H"
30
31// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33bool Foam::UOPBstream::bufferIPCsend()
34{
35 // Uses double broadcast
36 // 1. for the data size
37 // 2. for the data itself
38 // With this information, can determine and resize receive buffer
39
41
42 // Broadcast #1 - data size
43 // Same data type must be used in UIPBstream::bufferIPCrecv()
44
45 int64_t count(sendBuf_.size());
47 {
49 << "Broadcast failure sending buffer size:"
50 << label(count) << " comm:" << comm_ << nl
52 return false;
53 }
54
55 // Broadcast #2 - data content
56 // - skip if there is no data to send
57 if
58 (
59 (count > 0) // ie, not empty
61 (
62 sendBuf_.data(),
63 sendBuf_.size(), // same as count
65 comm_
66 )
67 )
68 {
70 << "Broadcast failure sending buffer data:"
71 << sendBuf_.size() << " comm:" << comm_ << nl
73 return false;
74 }
75
76 return true;
77}
78
79
80// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
81
82void Foam::UOPBstream::send(Foam::zero, int communicator, int root)
83{
84 if (UPstream::is_parallel(communicator))
85 {
86 int64_t count(0);
87 PstreamGlobals::broadcast_int64(count, communicator, root);
88 }
89 else
90 {
91 // FatalError ?
92 }
93}
94
95
96// ************************************************************************* //
static void send(Foam::zero, int communicator, int root=0)
Broadcast a zero value (buffer) size that can be matched by the UIPBstream constructor.
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
const int comm_
The communicator index.
Definition UOPstream.H:118
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.
static bool is_parallel(const label communicator=worldComm)
True if parallel algorithm or exchange is required.
Definition UPstream.H:1743
@ 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.
void checkCommunicator(int comm, int rank)
Fatal if communicator is outside the allocated range.
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