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 -------------------------------------------------------------------------------
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 #include <mpi.h>
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 bool Foam::UOPstream::bufferIPCsend()
38 {
39  return UOPstream::write
40  (
41  commsType(),
42  toProcNo_,
43  sendBuf_.cdata(),
44  sendBuf_.size(),
45  tag_,
46  comm_
47  );
48 }
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
54 (
55  const UPstream::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  << " commType:" << 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  << " commType:" << 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,
147  PstreamGlobals::MPICommunicators_[communicator],
148  &request
149  );
150 
152 
153  if (debug)
154  {
155  Pout<< "UOPstream::write : started write to:" << toProcNo
156  << " tag:" << tag << " size:" << label(bufSize)
157  << " commType:" << UPstream::commsTypeNames[commsType]
158  << " request:" << PstreamGlobals::outstandingRequests_.size()
159  << Foam::endl;
160  }
161 
162  PstreamGlobals::outstandingRequests_.push_back(request);
163  }
164  else
165  {
167  << "Unsupported communications type " << int(commsType)
169  }
170 
171  return !failed;
172 }
173 
174 
175 // ************************************************************************* //
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)
Write buffer contents to given processor.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
DynamicList< MPI_Request > outstandingRequests_
Outstanding non-blocking operations.
static const Enum< commsTypes > commsTypeNames
Enumerated names for the communication types.
Definition: UPstream.H:76
commsTypes
Types of communications.
Definition: UPstream.H:66
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:578
DynamicList< MPI_Comm > MPICommunicators_
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
void checkCommunicator(const label comm, const label toProcNo)
Fatal if comm is outside the allocated range.
static void addWaitTime()
Add time increment to wait time.
static void printStack(Ostream &os)
Helper function to print a stack.
const label comm_
Definition: UOPstream.H:107
DynamicList< char > & sendBuf_
Definition: UOPstream.H:103
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:366
errorManip< error > abort(error &err)
Definition: errorManip.H:139
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:814
static void beginTiming()
Update timer prior to measurement.
int debug
Static debugging option.
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:223
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.