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