UOPstreamWrite.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-2017 OpenFOAM Foundation
9 Copyright (C) 2019-2022 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 "PstreamGlobals.H"
31#include "profilingPstream.H"
32
33#include <mpi.h>
34
35// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36
37bool Foam::UOPstream::bufferIPCsend()
38{
39 return UOPstream::write
40 (
41 commsType(),
44 sendBuf_.size(),
45 tag_,
46 comm_
47 );
48}
49
50
51// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52
54(
55 const commsTypes commsType,
56 const int toProcNo,
57 const char* buf,
58 const std::streamsize bufSize,
59 const int tag,
60 const label communicator
61)
62{
63 if (debug)
64 {
65 Pout<< "UOPstream::write : starting write to:" << toProcNo
66 << " tag:" << tag
67 << " comm:" << communicator << " size:" << label(bufSize)
68 << " commsType:" << UPstream::commsTypeNames[commsType]
69 << Foam::endl;
70 }
71 if (UPstream::warnComm != -1 && communicator != UPstream::warnComm)
72 {
73 Pout<< "UOPstream::write : starting write to:" << toProcNo
74 << " tag:" << tag
75 << " comm:" << communicator << " size:" << label(bufSize)
76 << " commsType:" << UPstream::commsTypeNames[commsType]
77 << " warnComm:" << UPstream::warnComm
78 << Foam::endl;
80 }
81
82
83 PstreamGlobals::checkCommunicator(communicator, toProcNo);
84
85
86 bool failed = true;
87
89
90 if (commsType == commsTypes::blocking)
91 {
92 failed = MPI_Bsend
93 (
94 const_cast<char*>(buf),
95 bufSize,
96 MPI_BYTE,
97 toProcNo,
98 tag,
100 );
101
102 // Assume these are from scatters ...
104
105 if (debug)
106 {
107 Pout<< "UOPstream::write : finished write to:" << toProcNo
108 << " tag:" << tag << " size:" << label(bufSize)
109 << " commsType:" << UPstream::commsTypeNames[commsType]
110 << Foam::endl;
111 }
112 }
113 else if (commsType == commsTypes::scheduled)
114 {
115 failed = MPI_Send
116 (
117 const_cast<char*>(buf),
118 bufSize,
119 MPI_BYTE,
120 toProcNo,
121 tag,
123 );
124
125 // Assume these are from scatters ...
127
128 if (debug)
129 {
130 Pout<< "UOPstream::write : finished write to:" << toProcNo
131 << " tag:" << tag << " size:" << label(bufSize)
132 << " commsType:" << UPstream::commsTypeNames[commsType]
133 << Foam::endl;
134 }
135 }
136 else if (commsType == commsTypes::nonBlocking)
137 {
138 MPI_Request request;
139
140 failed = MPI_Isend
141 (
142 const_cast<char*>(buf),
143 bufSize,
144 MPI_BYTE,
145 toProcNo,
146 tag,
148 &request
149 );
150
152
153 if (debug)
154 {
155 Pout<< "UOPstream::write : started write to:" << toProcNo
156 << " tag:" << tag << " size:" << label(bufSize)
157 << " commsType:" << UPstream::commsTypeNames[commsType]
158 << " request:" << PstreamGlobals::outstandingRequests_.size()
159 << Foam::endl;
160 }
161
163 }
164 else
165 {
167 << "Unsupported communications type " << int(commsType)
169 }
170
171 return !failed;
172}
173
174
175// ************************************************************************* //
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:230
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
DynamicList< char > & sendBuf_
Definition: UOPstream.H:96
const int tag_
Definition: UOPstream.H:98
const label comm_
Definition: UOPstream.H:100
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:296
static const Enum< commsTypes > commsTypeNames
Names of the communication types.
Definition: UPstream.H:74
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:562
static void printStack(Ostream &os)
Helper function to print a stack.
virtual bool write()
Write the output fields.
static void addScatterTime()
Add time increment to scatterTime.
static void beginTiming()
Update timer prior to measurement.
static void addWaitTime()
Add time increment to waitTime.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
DynamicList< MPI_Request > outstandingRequests_
Outstanding non-blocking operations.
void checkCommunicator(const label comm, const label toProcNo)
DynamicList< MPI_Comm > MPICommunicators_
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.