Nektar++
CommSerial.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File CommSerial.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Serial (= no) communication implementation
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/core/ignore_unused.hpp>
36 
37 #ifdef NEKTAR_USING_PETSC
38 #include "petscsys.h"
39 #endif
40 
42 
43 namespace Nektar
44 {
45 namespace LibUtilities
46 {
48  "Serial", CommSerial::create, "Single-process serial communication.");
49 
50 CommSerial::CommSerial(int argc, char *argv[]) : Comm(argc, argv)
51 {
52 #ifdef NEKTAR_USING_PETSC
53  PetscInitializeNoArguments();
54 #endif
55  m_size = 1;
56  m_type = "Serial";
57 }
58 
59 CommSerial::~CommSerial() = default;
60 
61 /**
62  *
63  */
65 {
66 #ifdef NEKTAR_USING_PETSC
67  PetscFinalize();
68 #endif
69 }
70 
71 /**
72  *
73  */
75 {
76  return 0;
77 }
78 
79 /**
80  *
81  */
83 {
84  return true;
85 }
86 
87 /**
88  *
89  */
91 {
92  return true;
93 }
94 
95 std::tuple<int, int, int> CommSerial::v_GetVersion()
96 {
97  return std::make_tuple(0, 0, 0);
98 }
99 
100 /**
101  *
102  */
104 {
105 }
106 
107 /**
108  *
109  */
111 {
112  return 0;
113 }
114 
115 /**
116  *
117  */
118 void CommSerial::v_Send(void *buf, int count, CommDataType dt, int dest)
119 {
120  boost::ignore_unused(buf, count, dt, dest);
121 }
122 
123 /**
124  *
125  */
126 void CommSerial::v_Recv(void *buf, int count, CommDataType dt, int source)
127 {
128  boost::ignore_unused(buf, count, dt, source);
129 }
130 
131 /**
132  *
133  */
134 void CommSerial::v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype,
135  int dest, void *recvbuf, int recvcount,
136  CommDataType recvtype, int source)
137 {
138  boost::ignore_unused(sendbuf, sendcount, sendtype, dest, recvbuf, recvcount,
139  recvtype, source);
140 }
141 
142 /**
143  *
144  */
145 void CommSerial::v_SendRecvReplace(void *buf, int count, CommDataType dt,
146  int pSendProc, int pRecvProc)
147 {
148  boost::ignore_unused(buf, count, dt, pSendProc, pRecvProc);
149 }
150 
151 /**
152  *
153  */
154 void CommSerial::v_AllReduce(void *buf, int count, CommDataType dt,
155  enum ReduceOperator pOp)
156 {
157  boost::ignore_unused(buf, count, dt, pOp);
158 }
159 
160 /**
161  *
162  */
163 void CommSerial::v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
164  void *recvbuf, int recvcount, CommDataType recvtype)
165 {
166  boost::ignore_unused(sendbuf, sendcount, sendtype, recvbuf, recvcount,
167  recvtype);
168 }
169 
170 /**
171  *
172  */
173 void CommSerial::v_AlltoAllv(void *sendbuf, int sendcounts[], int sdispls[],
174  CommDataType sendtype, void *recvbuf,
175  int recvcounts[], int rdispls[],
176  CommDataType recvtype)
177 {
178  boost::ignore_unused(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
179  recvcounts, rdispls, recvtype);
180 }
181 
182 /**
183  *
184  */
185 void CommSerial::v_AllGather(void *sendbuf, int sendcount,
186  CommDataType sendtype, void *recvbuf,
187  int recvcount, CommDataType recvtype)
188 {
189  boost::ignore_unused(sendbuf, sendcount, sendtype, recvbuf, recvcount,
190  recvtype);
191 }
192 
193 void CommSerial::v_AllGatherv(void *sendbuf, int sendcount,
194  CommDataType sendtype, void *recvbuf,
195  int recvcounts[], int rdispls[],
196  CommDataType recvtype)
197 {
198  boost::ignore_unused(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
199  rdispls, recvtype);
200 }
201 
202 void CommSerial::v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[],
203  CommDataType recvtype)
204 {
205  boost::ignore_unused(recvbuf, recvcounts, rdispls, recvtype);
206 }
207 
208 void CommSerial::v_Bcast(void *buffer, int count, CommDataType dt, int root)
209 {
210  boost::ignore_unused(buffer, count, dt, root);
211 }
212 
214  const enum ReduceOperator pOp,
216 {
217  boost::ignore_unused(pData, pOp, ans);
218 }
219 
220 void CommSerial::v_Gather(void *sendbuf, int sendcount, CommDataType sendtype,
221  void *recvbuf, int recvcount, CommDataType recvtype,
222  int root)
223 {
224  boost::ignore_unused(recvcount, recvtype, root);
225  std::memcpy(recvbuf, sendbuf, sendcount * CommDataTypeGetSize(sendtype));
226 }
227 
228 void CommSerial::v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype,
229  void *recvbuf, int recvcount, CommDataType recvtype,
230  int root)
231 {
232  boost::ignore_unused(recvcount, recvtype, root);
233  std::memcpy(recvbuf, sendbuf, sendcount * CommDataTypeGetSize(sendtype));
234 }
235 
236 void CommSerial::v_DistGraphCreateAdjacent(int indegree, const int sources[],
237  const int sourceweights[],
238  int reorder)
239 {
240  boost::ignore_unused(indegree, sources, sourceweights, reorder);
241 }
242 
243 void CommSerial::v_NeighborAlltoAllv(void *sendbuf, int sendcounts[],
244  int senddispls[], CommDataType sendtype,
245  void *recvbuf, int recvcounts[],
246  int rdispls[], CommDataType recvtype)
247 {
248  boost::ignore_unused(sendbuf, sendcounts, senddispls, sendtype, recvbuf,
249  recvcounts, rdispls, recvtype);
250 }
251 
252 void CommSerial::v_Irsend(void *buf, int count, CommDataType dt, int dest,
253  CommRequestSharedPtr request, int loc)
254 {
255  boost::ignore_unused(buf, count, dt, dest, request, loc);
256 }
257 
258 void CommSerial::v_SendInit(void *buf, int count, CommDataType dt, int dest,
259  CommRequestSharedPtr request, int loc)
260 {
261  boost::ignore_unused(buf, count, dt, dest, request, loc);
262 }
263 
264 void CommSerial::v_Irecv(void *buf, int count, CommDataType dt, int source,
265  CommRequestSharedPtr request, int loc)
266 {
267  boost::ignore_unused(buf, count, dt, source, request, loc);
268 }
269 
270 void CommSerial::v_RecvInit(void *buf, int count, CommDataType dt, int source,
271  CommRequestSharedPtr request, int loc)
272 {
273  boost::ignore_unused(buf, count, dt, source, request, loc);
274 }
275 
277 {
278  boost::ignore_unused(request);
279 }
280 
282 {
283  boost::ignore_unused(request);
284 }
285 
287 {
288  boost::ignore_unused(num);
289  return std::shared_ptr<CommRequest>(new CommRequest);
290 }
291 
292 /**
293  *
294  */
295 void CommSerial::v_SplitComm(int pRows, int pColumns)
296 {
297  boost::ignore_unused(pRows, pColumns);
298  ASSERTL0(false, "Cannot split a serial process.");
299 }
300 
301 /**
302  *
303  */
305 {
306  if (flag == 0)
307  {
308  // flag == 0 => get back MPI_COMM_NULL, return a null ptr instead.
309  return std::shared_ptr<Comm>();
310  }
311  else
312  {
313  // Return a real communicator
314  return shared_from_this();
315  }
316 }
317 } // namespace LibUtilities
318 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
Base communications class.
Definition: Comm.h:90
int m_size
Number of processes.
Definition: Comm.h:175
std::string m_type
Type of communication.
Definition: Comm.h:176
Class for communicator request type.
Definition: Comm.h:78
virtual std::tuple< int, int, int > v_GetVersion() final
Definition: CommSerial.cpp:95
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc) final
Definition: CommSerial.cpp:145
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition: CommSerial.cpp:220
virtual CommSharedPtr v_CommCreateIf(int flag) final
Definition: CommSerial.cpp:304
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) final
Definition: CommSerial.cpp:134
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root) final
Definition: CommSerial.cpp:208
virtual CommRequestSharedPtr v_CreateRequest(int num) final
Definition: CommSerial.cpp:286
virtual void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
Definition: CommSerial.cpp:264
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) final
Definition: CommSerial.cpp:154
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
Definition: CommSerial.h:58
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, const enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans) final
Definition: CommSerial.cpp:213
virtual void v_SplitComm(int pRows, int pColumns) override
Definition: CommSerial.cpp:295
virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
Definition: CommSerial.cpp:270
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommSerial.cpp:173
virtual void v_Finalise() final
Definition: CommSerial.cpp:64
virtual void v_StartAll(CommRequestSharedPtr request) final
Definition: CommSerial.cpp:281
virtual bool v_TreatAsRankZero() override
Definition: CommSerial.cpp:82
CommSerial(int argc, char *argv[])
Definition: CommSerial.cpp:50
virtual NekDouble v_Wtime() final
Definition: CommSerial.cpp:110
static std::string className
Name of class.
Definition: CommSerial.h:64
virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommSerial.cpp:243
virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommSerial.cpp:252
virtual void v_Block() final
Definition: CommSerial.cpp:103
virtual void v_Send(void *buf, int count, CommDataType dt, int dest) final
Definition: CommSerial.cpp:118
virtual ~CommSerial() override
virtual bool v_IsSerial() override
Definition: CommSerial.cpp:90
virtual void v_WaitAll(CommRequestSharedPtr request) final
Definition: CommSerial.cpp:276
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommSerial.cpp:193
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition: CommSerial.cpp:163
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition: CommSerial.cpp:228
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition: CommSerial.cpp:185
virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[], const int sourceweights[], int reorder) final
Definition: CommSerial.cpp:236
virtual void v_Recv(void *buf, int count, CommDataType dt, int source) final
Definition: CommSerial.cpp:126
virtual int v_GetRank() override
Definition: CommSerial.cpp:74
virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommSerial.cpp:258
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
array buffer
Definition: GsLib.hpp:61
unsigned int CommDataType
Definition: CommDataType.h:70
std::shared_ptr< CommRequest > CommRequestSharedPtr
Definition: Comm.h:86
CommFactory & GetCommFactory()
ReduceOperator
Type of operation to perform in AllReduce.
Definition: Comm.h:67
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
int CommDataTypeGetSize(CommDataType dt)
Return the size in bytes of a data type dt.
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble