FreeFOAM The Cross-Platform CFD Toolkit
mpiOPstreamImpl.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 mpiOPstreamImpl
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "mpi.h"
30 
31 #include "mpiOPstreamImpl.H"
32 #include "mpiPstreamGlobals.H"
34 #include <OpenFOAM/Pstream.H>
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 defineTypeNameAndDebug(mpiOPstreamImpl, 0);
42 addToRunTimeSelectionTable(OPstreamImpl, mpiOPstreamImpl, dictionary);
43 
44 }
45 
46 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
47 
49 (
50  const PstreamImpl::commsTypes commsType,
51  const int toProcNo,
52  const char* buf,
53  const int bufPosition
54 )
55 {
56  if
57  (
58  !write
59  (
60  commsType,
61  toProcNo,
62  buf,
63  bufPosition
64  )
65  )
66  {
67  FatalErrorIn("mpiOPstreamImpl::flush(const PstreamImpl::commsTypes, "
68  "const int, const char*, const int)")
69  << "MPI_Bsend cannot send outgoing message"
71  }
72 }
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
77 (
78  const PstreamImpl::commsTypes commsType,
79  const int toProcNo,
80  const char* buf,
81  const std::streamsize bufSize
82 )
83 {
84  bool transferFailed = true;
85 
86  if (commsType == PstreamImpl::blocking)
87  {
88  transferFailed = MPI_Bsend
89  (
90  const_cast<char*>(buf),
91  bufSize,
92  MPI_PACKED,
93  Pstream::procID(toProcNo),
94  Pstream::msgType(),
95  MPI_COMM_WORLD
96  );
97  }
98  else if (commsType == PstreamImpl::scheduled)
99  {
100  transferFailed = MPI_Send
101  (
102  const_cast<char*>(buf),
103  bufSize,
104  MPI_PACKED,
105  Pstream::procID(toProcNo),
106  Pstream::msgType(),
107  MPI_COMM_WORLD
108  );
109  }
110  else if (commsType == PstreamImpl::nonBlocking)
111  {
112  MPI_Request request;
113 
114  transferFailed = MPI_Isend
115  (
116  const_cast<char*>(buf),
117  bufSize,
118  MPI_PACKED,
119  Pstream::procID(toProcNo),
120  Pstream::msgType(),
121  MPI_COMM_WORLD,
122  &request
123  );
124 
126  }
127  else
128  {
130  (
131  "mpiOPstreamImpl::write"
132  "(const int fromProcNo, char* buf, std::streamsize bufSize)"
133  ) << "Unsupported communications type " << commsType
135  }
136 
137  return !transferFailed;
138 }
139 
140 
142 {
144  {
145  if
146  (
147  MPI_Waitall
148  (
151  MPI_STATUSES_IGNORE
152  )
153  )
154  {
156  (
157  "mpiOPstreamImpl::waitRequests()"
158  ) << "MPI_Waitall returned with error" << Foam::endl;
159  }
160 
162  }
163 }
164 
165 
167 {
169  {
171  (
172  "OPstream::finishedRequest(const label)"
173  "mpiOPstreamImpl::finishedRequest(const label)"
174  ) << "There are "
176  << " outstanding send requests and you are asking for i=" << i
177  << nl
178  << "Maybe you are mixing blocking/non-blocking comms?"
180  }
181 
182  int flag;
183  MPI_Test
184  (
186  &flag,
187  MPI_STATUS_IGNORE
188  );
189 
190  return flag != 0;
191 }
192 
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 // ************************ vim: set sw=4 sts=4 et: ************************ //