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-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 bool Foam::UOPstream::bufferIPCsend()
36 {
37  return UOPstream::write
38  (
39  commsType(),
40  toProcNo_,
41  sendBuf_.cdata(),
42  sendBuf_.size(),
43  tag_,
44  comm_
45  );
46 }
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
52 (
53  const UPstream::commsTypes commsType,
54  const int toProcNo,
55  const char* buf,
56  const std::streamsize bufSize,
57  const int tag,
58  const label communicator,
59  UPstream::Request* req,
60  const UPstream::sendModes sendMode
61 )
62 {
64 
65  if (UPstream::debug)
66  {
67  Pout<< "UOPstream::write : starting write to:" << toProcNo
68  << " tag:" << tag
69  << " comm:" << communicator << " size:" << label(bufSize)
70  << " commType:" << UPstream::commsTypeNames[commsType]
71  << Foam::endl;
72  }
73  if (UPstream::warnComm >= 0 && communicator != UPstream::warnComm)
74  {
75  Pout<< "UOPstream::write : starting write to:" << toProcNo
76  << " tag:" << tag
77  << " comm:" << communicator << " size:" << label(bufSize)
78  << " commType:" << UPstream::commsTypeNames[commsType]
79  << " warnComm:" << UPstream::warnComm
80  << Foam::endl;
82  }
83 
84  PstreamGlobals::checkCommunicator(communicator, toProcNo);
85 
86  int returnCode = MPI_ERR_UNKNOWN;
87 
89 
90  if (commsType == UPstream::commsTypes::blocking)
91  {
92  returnCode = 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 (UPstream::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 == UPstream::commsTypes::scheduled)
114  {
115  if (UPstream::sendModes::sync == sendMode)
116  {
117  returnCode = MPI_Ssend
118  (
119  const_cast<char*>(buf),
120  bufSize,
121  MPI_BYTE,
122  toProcNo,
123  tag,
125  );
126  }
127  else
128  {
129  returnCode = MPI_Send
130  (
131  const_cast<char*>(buf),
132  bufSize,
133  MPI_BYTE,
134  toProcNo,
135  tag,
137  );
138  }
139 
140  // Assume these are from scatters ...
142 
143  if (UPstream::debug)
144  {
145  Pout<< "UOPstream::write : finished write to:" << toProcNo
146  << " tag:" << tag << " size:" << label(bufSize)
147  << " commsType:" << UPstream::commsTypeNames[commsType]
148  << Foam::endl;
149  }
150  }
151  else if (commsType == UPstream::commsTypes::nonBlocking)
152  {
153  MPI_Request request;
154 
155  if (UPstream::sendModes::sync == sendMode)
156  {
157  returnCode = MPI_Issend
158  (
159  const_cast<char*>(buf),
160  bufSize,
161  MPI_BYTE,
162  toProcNo,
163  tag,
164  PstreamGlobals::MPICommunicators_[communicator],
165  &request
166  );
167  }
168  else
169  {
170  returnCode = MPI_Isend
171  (
172  const_cast<char*>(buf),
173  bufSize,
174  MPI_BYTE,
175  toProcNo,
176  tag,
177  PstreamGlobals::MPICommunicators_[communicator],
178  &request
179  );
180  }
181 
182  if (UPstream::debug)
183  {
184  Pout<< "UOPstream::write : started write to:" << toProcNo
185  << " tag:" << tag << " size:" << label(bufSize)
186  << " commType:" << UPstream::commsTypeNames[commsType]
187  << " request:" <<
188  (req ? label(-1) : PstreamGlobals::outstandingRequests_.size())
189  << Foam::endl;
190  }
191 
192  PstreamGlobals::push_request(request, req);
194  }
195  else
196  {
198  << "Unsupported communications type " << int(commsType)
200  }
201 
202  return (returnCode == MPI_SUCCESS);
203 }
204 
205 
206 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
sendModes
Different MPI-send modes (ignored for commsTypes::blocking)
Definition: UPstream.H:87
"blocking" : (MPI_Bsend, MPI_Recv)
DynamicList< MPI_Request > outstandingRequests_
Outstanding non-blocking operations.
static const Enum< commsTypes > commsTypeNames
Enumerated names for the communication types.
Definition: UPstream.H:82
commsTypes
Communications types.
Definition: UPstream.H:72
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
const int comm_
The communicator index.
Definition: UOPstream.H:117
DynamicList< MPI_Comm > MPICommunicators_
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
void reset_request(UPstream::Request *requestPtr, label *requestIdx=nullptr)
Reset UPstream::Request to null and/or the index of the outstanding request to -1.
void checkCommunicator(const label comm, const label toProcNo)
Fatal if comm is outside the allocated range.
"scheduled" : (MPI_Send, MPI_Recv)
const int toProcNo_
Destination rank for the data.
Definition: UOPstream.H:107
DynamicList< char > & sendBuf_
Reference to the send buffer data.
Definition: UOPstream.H:127
static void addScatterTime()
Add time increment to scatter time.
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:414
errorManip< error > abort(error &err)
Definition: errorManip.H:139
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:1261
(MPI_Ssend, MPI_Issend)
static void beginTiming()
Update timer prior to measurement.
int debug
Static debugging option.
static void addRequestTime()
Add time increment to request time.
void push_request(MPI_Request request, UPstream::Request *requestPtr=nullptr, label *requestIdx=nullptr)
Transcribe MPI_Request to UPstream::Request (does not affect the stack of outstanding requests) or el...
static bool write(const UPstream::commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, UPstream::Request *req=nullptr, const UPstream::sendModes sendMode=UPstream::sendModes::normal)
Write buffer contents to given processor.
"nonBlocking" : (MPI_Isend, MPI_Irecv)
static void printStack(Ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit.
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:265
const int tag_
Message tag for communication.
Definition: UOPstream.H:112
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Namespace for OpenFOAM.