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
43namespace Nektar
44{
45namespace LibUtilities
46{
48 "Serial", CommSerial::create, "Single-process serial communication.");
49
50CommSerial::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
59CommSerial::~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/**
96 *
97 */
98std::tuple<int, int, int> CommSerial::v_GetVersion()
99{
100 return std::make_tuple(0, 0, 0);
101}
102
103/**
104 *
105 */
107{
108}
109
110/**
111 *
112 */
114{
115 return 0;
116}
117
118/**
119 *
120 */
121void CommSerial::v_Send(void *buf, int count, CommDataType dt, int dest)
122{
123 boost::ignore_unused(buf, count, dt, dest);
124}
125
126/**
127 *
128 */
129void CommSerial::v_Recv(void *buf, int count, CommDataType dt, int source)
130{
131 boost::ignore_unused(buf, count, dt, source);
132}
133
134/**
135 *
136 */
137void CommSerial::v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype,
138 int dest, void *recvbuf, int recvcount,
139 CommDataType recvtype, int source)
140{
141 boost::ignore_unused(sendbuf, sendcount, sendtype, dest, recvbuf, recvcount,
142 recvtype, source);
143}
144
145/**
146 *
147 */
148void CommSerial::v_AllReduce(void *buf, int count, CommDataType dt,
149 enum ReduceOperator pOp)
150{
151 boost::ignore_unused(buf, count, dt, pOp);
152}
153
154/**
155 *
156 */
157void CommSerial::v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
158 void *recvbuf, int recvcount, CommDataType recvtype)
159{
160 boost::ignore_unused(sendbuf, sendcount, sendtype, recvbuf, recvcount,
161 recvtype);
162}
163
164/**
165 *
166 */
167void CommSerial::v_AlltoAllv(void *sendbuf, int sendcounts[], int sdispls[],
168 CommDataType sendtype, void *recvbuf,
169 int recvcounts[], int rdispls[],
170 CommDataType recvtype)
171{
172 boost::ignore_unused(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
173 recvcounts, rdispls, recvtype);
174}
175
176/**
177 *
178 */
179void CommSerial::v_AllGather(void *sendbuf, int sendcount,
180 CommDataType sendtype, void *recvbuf,
181 int recvcount, CommDataType recvtype)
182{
183 boost::ignore_unused(sendbuf, sendcount, sendtype, recvbuf, recvcount,
184 recvtype);
185}
186
187/**
188 *
189 */
190void CommSerial::v_AllGatherv(void *sendbuf, int sendcount,
191 CommDataType sendtype, void *recvbuf,
192 int recvcounts[], int rdispls[],
193 CommDataType recvtype)
194{
195 boost::ignore_unused(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
196 rdispls, recvtype);
197}
198
199/**
200 *
201 */
202void CommSerial::v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[],
203 CommDataType recvtype)
204{
205 boost::ignore_unused(recvbuf, recvcounts, rdispls, recvtype);
206}
207
208/**
209 *
210 */
211void CommSerial::v_Bcast(void *buffer, int count, CommDataType dt, int root)
212{
213 boost::ignore_unused(buffer, count, dt, root);
214}
215
216/**
217 *
218 */
219void CommSerial::v_Gather(void *sendbuf, int sendcount, CommDataType sendtype,
220 void *recvbuf, int recvcount, CommDataType recvtype,
221 int root)
222{
223 boost::ignore_unused(recvcount, recvtype, root);
224 std::memcpy(recvbuf, sendbuf, sendcount * CommDataTypeGetSize(sendtype));
225}
226
227/**
228 *
229 */
230void CommSerial::v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype,
231 void *recvbuf, int recvcount, CommDataType recvtype,
232 int root)
233{
234 boost::ignore_unused(recvcount, recvtype, root);
235 std::memcpy(recvbuf, sendbuf, sendcount * CommDataTypeGetSize(sendtype));
236}
237
238/**
239 *
240 */
241void CommSerial::v_DistGraphCreateAdjacent(int indegree, const int sources[],
242 const int sourceweights[],
243 int reorder)
244{
245 boost::ignore_unused(indegree, sources, sourceweights, reorder);
246}
247
248/**
249 *
250 */
251void CommSerial::v_NeighborAlltoAllv(void *sendbuf, int sendcounts[],
252 int senddispls[], CommDataType sendtype,
253 void *recvbuf, int recvcounts[],
254 int rdispls[], CommDataType recvtype)
255{
256 boost::ignore_unused(sendbuf, sendcounts, senddispls, sendtype, recvbuf,
257 recvcounts, rdispls, recvtype);
258}
259
260/**
261 *
262 */
263void CommSerial::v_Irsend(void *buf, int count, CommDataType dt, int dest,
264 CommRequestSharedPtr request, int loc)
265{
266 boost::ignore_unused(buf, count, dt, dest, request, loc);
267}
268
269/**
270 *
271 */
272void CommSerial::v_Isend(void *buf, int count, CommDataType dt, int dest,
273 CommRequestSharedPtr request, int loc)
274{
275 boost::ignore_unused(buf, count, dt, dest, request, loc);
276}
277
278/**
279 *
280 */
281void CommSerial::v_SendInit(void *buf, int count, CommDataType dt, int dest,
282 CommRequestSharedPtr request, int loc)
283{
284 boost::ignore_unused(buf, count, dt, dest, request, loc);
285}
286
287/**
288 *
289 */
290void CommSerial::v_Irecv(void *buf, int count, CommDataType dt, int source,
291 CommRequestSharedPtr request, int loc)
292{
293 boost::ignore_unused(buf, count, dt, source, request, loc);
294}
295
296/**
297 *
298 */
299void CommSerial::v_RecvInit(void *buf, int count, CommDataType dt, int source,
300 CommRequestSharedPtr request, int loc)
301{
302 boost::ignore_unused(buf, count, dt, source, request, loc);
303}
304
305/**
306 *
307 */
309{
310 boost::ignore_unused(request);
311}
312
313/**
314 *
315 */
317{
318 boost::ignore_unused(request);
319}
320
321/**
322 *
323 */
325{
326 boost::ignore_unused(num);
327 return std::shared_ptr<CommRequest>(new CommRequest);
328}
329
330/**
331 *
332 */
333void CommSerial::v_SplitComm(int pRows, int pColumns, int pTime)
334{
335 boost::ignore_unused(pRows, pColumns, pTime);
336 ASSERTL0(false, "Cannot split a serial process.");
337}
338
339/**
340 *
341 */
343{
344 if (flag == 0)
345 {
346 // flag == 0 => get back MPI_COMM_NULL, return a null ptr instead.
347 return std::shared_ptr<Comm>();
348 }
349 else
350 {
351 // Return a real communicator
352 return shared_from_this();
353 }
354}
355
356} // namespace LibUtilities
357} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
Base communications class.
Definition: Comm.h:90
int m_size
Number of processes.
Definition: Comm.h:176
std::string m_type
Type of communication.
Definition: Comm.h:177
Class for communicator request type.
Definition: Comm.h:78
virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) override final
Definition: CommSerial.cpp:281
virtual NekDouble v_Wtime() override final
Definition: CommSerial.cpp:113
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) override final
Definition: CommSerial.cpp:190
virtual void v_Recv(void *buf, int count, CommDataType dt, int source) override final
Definition: CommSerial.cpp:129
virtual void v_WaitAll(CommRequestSharedPtr request) override final
Definition: CommSerial.cpp:316
virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[], const int sourceweights[], int reorder) override final
Definition: CommSerial.cpp:241
virtual void v_Finalise() override final
Definition: CommSerial.cpp:64
virtual void v_Send(void *buf, int count, CommDataType dt, int dest) override final
Definition: CommSerial.cpp:121
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
Definition: CommSerial.h:58
virtual void v_SplitComm(int pRows, int pColumns, int pTime) override
Definition: CommSerial.cpp:333
virtual void v_Isend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommSerial.cpp:272
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) override final
Definition: CommSerial.cpp:219
virtual bool v_TreatAsRankZero() override
Definition: CommSerial.cpp:82
virtual CommRequestSharedPtr v_CreateRequest(int num) override final
Definition: CommSerial.cpp:324
CommSerial(int argc, char *argv[])
Definition: CommSerial.cpp:50
virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) override final
Definition: CommSerial.cpp:263
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) override final
Definition: CommSerial.cpp:167
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) override final
Definition: CommSerial.cpp:148
virtual void v_Block() override final
Definition: CommSerial.cpp:106
static std::string className
Name of class.
Definition: CommSerial.h:64
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) override final
Definition: CommSerial.cpp:137
virtual CommSharedPtr v_CommCreateIf(int flag) override final
Definition: CommSerial.cpp:342
virtual ~CommSerial() override
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root) override final
Definition: CommSerial.cpp:211
virtual bool v_IsSerial() override
Definition: CommSerial.cpp:90
virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) override final
Definition: CommSerial.cpp:251
virtual void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) override final
Definition: CommSerial.cpp:290
virtual void v_StartAll(CommRequestSharedPtr request) override final
Definition: CommSerial.cpp:308
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) override final
Definition: CommSerial.cpp:230
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) override final
Definition: CommSerial.cpp:179
virtual int v_GetRank() override
Definition: CommSerial.cpp:74
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) override final
Definition: CommSerial.cpp:157
virtual std::tuple< int, int, int > v_GetVersion() override final
Definition: CommSerial.cpp:98
virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) override final
Definition: CommSerial.cpp:299
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
array buffer
Definition: GsLib.hpp:83
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:57
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:2
double NekDouble