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 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#include <mpi.h>
32
33// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34
35bool Foam::UOPBstream::bufferIPCsend()
36{
37 // Uses double broadcast
38 // 1. for the data size
39 // 2. for the data itself
40 // With this information, can determine and resize receive buffer
41
43
44 // Same type must be expected in UIPBstream::bufferIPCrecv()
45 label bufSize(sendBuf_.size());
46
47 // Broadcast #1 - data size
48 if
49 (
51 (
52 reinterpret_cast<char*>(&bufSize),
53 sizeof(label),
54 comm_,
55 toProcNo_ //< is actually rootProcNo
56 )
57 )
58 {
60 << "MPI_Bcast failure sending buffer size:" << bufSize << nl
62 return false;
63 }
64
65 // Broadcast #2 - data content
66 // - skip if there is no data to send
67 if (bufSize)
68 {
69 if
70 (
72 (
73 sendBuf_.data(),
74 sendBuf_.size(), // same as bufSize
75 comm_,
76 toProcNo_ //< is actually rootProcNo
77 )
78 )
79 {
81 << "MPI_Bcast failure sending buffer data:" << bufSize << nl
83 return false;
84 }
85 }
86
87 return true;
88}
89
90
91// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92
94(
95 const commsTypes commsType, /* unused */
96 const int rootProcNo,
97 const char* buf,
98 const std::streamsize bufSize,
99 const int tag, /* unused */
100 const label comm
101)
102{
103 if
104 (
105 !UPstream::broadcast(const_cast<char*>(buf), bufSize, comm, rootProcNo)
106 )
107 {
109 << "MPI_Bcast failure sending buffer data:" << label(bufSize) << nl
111 return false;
112 }
113
114 return true;
115}
116
117
118// ************************************************************************* //
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:237
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
DynamicList< char > & sendBuf_
Definition: UOPstream.H:96
const label comm_
Definition: UOPstream.H:100
static bool broadcast(char *buf, const std::streamsize bufSize, const label communicator=worldComm, const int rootProcNo=masterNo())
virtual bool write()
Write the output fields.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
void checkCommunicator(const label comm, const label toProcNo)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53