UOPwrite.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Write primitive and binary block from OPstream
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "UOPstream.H"
30 #include "PstreamGlobals.H"
31 
32 #include <mpi.h>
33 
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35 
37 (
38  const commsTypes commsType,
39  const int toProcNo,
40  const char* buf,
41  const std::streamsize bufSize,
42  const int tag,
43  const label communicator
44 )
45 {
46  if (debug)
47  {
48  Pout<< "UOPstream::write : starting write to:" << toProcNo
49  << " tag:" << tag
50  << " comm:" << communicator << " size:" << label(bufSize)
51  << " commsType:" << UPstream::commsTypeNames[commsType]
52  << Foam::endl;
53  }
54  if (UPstream::warnComm != -1 && communicator != UPstream::warnComm)
55  {
56  Pout<< "UOPstream::write : starting write to:" << toProcNo
57  << " tag:" << tag
58  << " comm:" << communicator << " size:" << label(bufSize)
59  << " commsType:" << UPstream::commsTypeNames[commsType]
60  << " warnComm:" << UPstream::warnComm
61  << Foam::endl;
63  }
64 
65 
66  PstreamGlobals::checkCommunicator(communicator, toProcNo);
67 
68 
69  bool transferFailed = true;
70 
71  if (commsType == commsTypes::blocking)
72  {
73  transferFailed = MPI_Bsend
74  (
75  const_cast<char*>(buf),
76  bufSize,
77  MPI_BYTE,
78  toProcNo, // procID(toProcNo),
79  tag,
81  );
82 
83  if (debug)
84  {
85  Pout<< "UOPstream::write : finished write to:" << toProcNo
86  << " tag:" << tag << " size:" << label(bufSize)
87  << " commsType:" << UPstream::commsTypeNames[commsType]
88  << Foam::endl;
89  }
90  }
91  else if (commsType == commsTypes::scheduled)
92  {
93  transferFailed = MPI_Send
94  (
95  const_cast<char*>(buf),
96  bufSize,
97  MPI_BYTE,
98  toProcNo, // procID(toProcNo),
99  tag,
101  );
102 
103  if (debug)
104  {
105  Pout<< "UOPstream::write : finished write to:" << toProcNo
106  << " tag:" << tag << " size:" << label(bufSize)
107  << " commsType:" << UPstream::commsTypeNames[commsType]
108  << Foam::endl;
109  }
110  }
111  else if (commsType == commsTypes::nonBlocking)
112  {
113  MPI_Request request;
114 
115  transferFailed = MPI_Isend
116  (
117  const_cast<char*>(buf),
118  bufSize,
119  MPI_BYTE,
120  toProcNo, // procID(toProcNo),
121  tag,
122  PstreamGlobals::MPICommunicators_[communicator],
123  &request
124  );
125 
126  if (debug)
127  {
128  Pout<< "UOPstream::write : started write to:" << toProcNo
129  << " tag:" << tag << " size:" << label(bufSize)
130  << " commsType:" << UPstream::commsTypeNames[commsType]
131  << " request:" << PstreamGlobals::outstandingRequests_.size()
132  << Foam::endl;
133  }
134 
135  PstreamGlobals::outstandingRequests_.append(request);
136  }
137  else
138  {
140  << "Unsupported communications type "
143  }
144 
145  return !transferFailed;
146 }
147 
148 
149 // ************************************************************************* //
static void printStack(Ostream &)
Helper function to print a stack.
commsTypes commsType() const
Get the communications type of the stream.
Definition: UPstream.H:481
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
DynamicList< MPI_Request > outstandingRequests_
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:281
errorManip< error > abort(error &err)
Definition: errorManip.H:131
static bool write(const commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Write given buffer to given processor.
Definition: UOPwrite.C:34
static const NamedEnum< commsTypes, 3 > commsTypeNames
Definition: UPstream.H:71
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
DynamicList< MPI_Comm > MPICommunicators_
void checkCommunicator(const label, const label procNo)