UOPwrite.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-2021 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 Description
28  Write primitive and binary block from OPstream
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "UOPstream.H"
33 #include "PstreamGlobals.H"
34 #include "profilingPstream.H"
35 
36 #include <mpi.h>
37 
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
39 
41 (
42  const commsTypes commsType,
43  const int toProcNo,
44  const char* buf,
45  const std::streamsize bufSize,
46  const int tag,
47  const label communicator
48 )
49 {
50  if (debug)
51  {
52  Pout<< "UOPstream::write : starting write to:" << toProcNo
53  << " tag:" << tag
54  << " comm:" << communicator << " size:" << label(bufSize)
55  << " commsType:" << UPstream::commsTypeNames[commsType]
56  << Foam::endl;
57  }
58  if (UPstream::warnComm != -1 && communicator != UPstream::warnComm)
59  {
60  Pout<< "UOPstream::write : starting write to:" << toProcNo
61  << " tag:" << tag
62  << " comm:" << communicator << " size:" << label(bufSize)
63  << " commsType:" << UPstream::commsTypeNames[commsType]
64  << " warnComm:" << UPstream::warnComm
65  << Foam::endl;
67  }
68 
69 
70  PstreamGlobals::checkCommunicator(communicator, toProcNo);
71 
72 
73  bool transferFailed = true;
74 
76 
78  {
79  transferFailed = MPI_Bsend
80  (
81  const_cast<char*>(buf),
82  bufSize,
83  MPI_BYTE,
84  toProcNo,
85  tag,
87  );
88 
89  // Assume these are from scatters ...
91 
92  if (debug)
93  {
94  Pout<< "UOPstream::write : finished write to:" << toProcNo
95  << " tag:" << tag << " size:" << label(bufSize)
96  << " commsType:" << UPstream::commsTypeNames[commsType]
97  << Foam::endl;
98  }
99  }
100  else if (commsType == commsTypes::scheduled)
101  {
102  transferFailed = MPI_Send
103  (
104  const_cast<char*>(buf),
105  bufSize,
106  MPI_BYTE,
107  toProcNo,
108  tag,
110  );
111 
112  // Assume these are from scatters ...
114 
115  if (debug)
116  {
117  Pout<< "UOPstream::write : finished write to:" << toProcNo
118  << " tag:" << tag << " size:" << label(bufSize)
119  << " commsType:" << UPstream::commsTypeNames[commsType]
120  << Foam::endl;
121  }
122  }
124  {
125  MPI_Request request;
126 
127  transferFailed = MPI_Isend
128  (
129  const_cast<char*>(buf),
130  bufSize,
131  MPI_BYTE,
132  toProcNo,
133  tag,
134  PstreamGlobals::MPICommunicators_[communicator],
135  &request
136  );
137 
139 
140  if (debug)
141  {
142  Pout<< "UOPstream::write : started write to:" << toProcNo
143  << " tag:" << tag << " size:" << label(bufSize)
144  << " commsType:" << UPstream::commsTypeNames[commsType]
145  << " request:" << PstreamGlobals::outstandingRequests_.size()
146  << Foam::endl;
147  }
148 
149  PstreamGlobals::outstandingRequests_.append(request);
150  }
151  else
152  {
154  << "Unsupported communications type "
157  }
158 
159  return !transferFailed;
160 }
161 
162 
163 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::UPstream::warnComm
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:296
Foam::UPstream::commsType
commsTypes commsType() const noexcept
Get the communications type of the stream.
Definition: UPstream.H:547
Foam::profilingPstream::addWaitTime
static void addWaitTime()
Add time increment to waitTime.
Definition: profilingPstream.H:174
Foam::error::printStack
static void printStack(Ostream &os)
Helper function to print a stack.
Definition: dummyPrintStack.C:36
Foam::PstreamGlobals::checkCommunicator
void checkCommunicator(const label comm, const label toProcNo)
Definition: PstreamGlobals.C:44
Foam::UOPstream::write
static bool write(const commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=UPstream::worldComm)
Write given buffer to given processor.
Definition: UOPwrite.C:36
Foam::profilingPstream::beginTiming
static void beginTiming()
Update timer prior to measurement.
Definition: profilingPstream.H:138
Foam::PstreamGlobals::outstandingRequests_
DynamicList< MPI_Request > outstandingRequests_
Outstanding non-blocking operations.
Definition: PstreamGlobals.C:32
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::profilingPstream::addScatterTime
static void addScatterTime()
Add time increment to scatterTime.
Definition: profilingPstream.H:162
Foam::PstreamGlobals::MPICommunicators_
DynamicList< MPI_Comm > MPICommunicators_
Definition: PstreamGlobals.C:39
Foam::UPstream::commsTypeNames
static const Enum< commsTypes > commsTypeNames
Names of the communication types.
Definition: UPstream.H:77
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
PstreamGlobals.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::UPstream::commsTypes::nonBlocking
UOPstream.H
Foam::UPstream::commsTypes::scheduled
Foam::UPstream::commsTypes::blocking
profilingPstream.H