Nektar++
Loading...
Searching...
No Matches
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]] const void *buf,
118 [[maybe_unused]] int count,
119 [[maybe_unused]] CommDataType dt,
120 [[maybe_unused]] int dest)
121{
122}
123
124/**
125 *
126 */
127void CommSerial::v_Recv([[maybe_unused]] void *buf, [[maybe_unused]] int count,
128 [[maybe_unused]] CommDataType dt,
129 [[maybe_unused]] int source)
130{
131}
132
133/**
134 *
135 */
137 [[maybe_unused]] const void *sendbuf, [[maybe_unused]] int sendcount,
138 [[maybe_unused]] CommDataType sendtype, [[maybe_unused]] int dest,
139 [[maybe_unused]] void *recvbuf, [[maybe_unused]] int recvcount,
140 [[maybe_unused]] CommDataType recvtype, [[maybe_unused]] int source)
141{
142}
143
144/**
145 *
146 */
147void CommSerial::v_AllReduce([[maybe_unused]] void *buf,
148 [[maybe_unused]] int count,
149 [[maybe_unused]] CommDataType dt,
150 [[maybe_unused]] enum ReduceOperator pOp)
151{
152}
153
154/**
155 *
156 */
157void CommSerial::v_AlltoAll([[maybe_unused]] const void *sendbuf,
158 [[maybe_unused]] int sendcount,
159 [[maybe_unused]] CommDataType sendtype,
160 [[maybe_unused]] void *recvbuf,
161 [[maybe_unused]] int recvcount,
162 [[maybe_unused]] CommDataType recvtype)
163{
164}
165
166/**
167 *
168 */
169void CommSerial::v_AlltoAllv([[maybe_unused]] const void *sendbuf,
170 [[maybe_unused]] const int *sendcounts,
171 [[maybe_unused]] const int *senddispls,
172 [[maybe_unused]] CommDataType sendtype,
173 [[maybe_unused]] void *recvbuf,
174 [[maybe_unused]] const int *recvcounts,
175 [[maybe_unused]] const int *recvdispls,
176 [[maybe_unused]] CommDataType recvtype)
177{
178}
179
180/**
181 *
182 */
183void CommSerial::v_AllGather([[maybe_unused]] const void *sendbuf,
184 [[maybe_unused]] int sendcount,
185 [[maybe_unused]] CommDataType sendtype,
186 [[maybe_unused]] void *recvbuf,
187 [[maybe_unused]] int recvcount,
188 [[maybe_unused]] CommDataType recvtype)
189{
190}
191
192/**
193 *
194 */
195void CommSerial::v_AllGatherv([[maybe_unused]] const void *sendbuf,
196 [[maybe_unused]] int sendcount,
197 [[maybe_unused]] CommDataType sendtype,
198 [[maybe_unused]] void *recvbuf,
199 [[maybe_unused]] const int *recvcounts,
200 [[maybe_unused]] const int *recvdispls,
201 [[maybe_unused]] CommDataType recvtype)
202{
203}
204
205/**
206 *
207 */
208void CommSerial::v_AllGatherv([[maybe_unused]] void *recvbuf,
209 [[maybe_unused]] const int *recvcounts,
210 [[maybe_unused]] const int *recvdispls,
211 [[maybe_unused]] CommDataType recvtype)
212{
213}
214
215/**
216 *
217 */
218void CommSerial::v_Bcast([[maybe_unused]] void *buffer,
219 [[maybe_unused]] int count,
220 [[maybe_unused]] CommDataType dt,
221 [[maybe_unused]] int root)
222{
223}
224
225/**
226 *
227 */
228void CommSerial::v_Gather(const void *sendbuf, int sendcount,
229 CommDataType sendtype, void *recvbuf,
230 [[maybe_unused]] int recvcount,
231 [[maybe_unused]] CommDataType recvtype,
232 [[maybe_unused]] int root)
233{
234 std::memcpy(recvbuf, sendbuf, sendcount * CommDataTypeGetSize(sendtype));
235}
236
237/**
238 *
239 */
240void CommSerial::v_Scatter(const void *sendbuf, int sendcount,
241 CommDataType sendtype, void *recvbuf,
242 [[maybe_unused]] int recvcount,
243 [[maybe_unused]] CommDataType recvtype,
244 [[maybe_unused]] int root)
245{
246 std::memcpy(recvbuf, sendbuf, sendcount * CommDataTypeGetSize(sendtype));
247}
248
249/**
250 *
251 */
253 [[maybe_unused]] int indegree, [[maybe_unused]] const int *sources,
254 [[maybe_unused]] const int *sourceweights, [[maybe_unused]] int reorder)
255{
256}
257
258/**
259 *
260 */
261void CommSerial::v_NeighborAlltoAllv([[maybe_unused]] const void *sendbuf,
262 [[maybe_unused]] const int *sendcounts,
263 [[maybe_unused]] const int *senddispls,
264 [[maybe_unused]] CommDataType sendtype,
265 [[maybe_unused]] void *recvbuf,
266 [[maybe_unused]] const int *recvcounts,
267 [[maybe_unused]] const int *recvdispls,
268 [[maybe_unused]] CommDataType recvtype)
269{
270}
271
272/**
273 *
274 */
275void CommSerial::v_Irsend([[maybe_unused]] const void *buf,
276 [[maybe_unused]] int count,
277 [[maybe_unused]] CommDataType dt,
278 [[maybe_unused]] int dest,
279 [[maybe_unused]] CommRequestSharedPtr request,
280 [[maybe_unused]] int loc)
281{
282}
283
284/**
285 *
286 */
287void CommSerial::v_Isend([[maybe_unused]] const void *buf,
288 [[maybe_unused]] int count,
289 [[maybe_unused]] CommDataType dt,
290 [[maybe_unused]] int dest,
291 [[maybe_unused]] CommRequestSharedPtr request,
292 [[maybe_unused]] int loc)
293{
294}
295
296/**
297 *
298 */
299void CommSerial::v_SendInit([[maybe_unused]] const void *buf,
300 [[maybe_unused]] int count,
301 [[maybe_unused]] CommDataType dt,
302 [[maybe_unused]] int dest,
303 [[maybe_unused]] CommRequestSharedPtr request,
304 [[maybe_unused]] int loc)
305{
306}
307
308/**
309 *
310 */
311void CommSerial::v_Irecv([[maybe_unused]] void *buf, [[maybe_unused]] int count,
312 [[maybe_unused]] CommDataType dt,
313 [[maybe_unused]] int source,
314 [[maybe_unused]] CommRequestSharedPtr request,
315 [[maybe_unused]] int loc)
316{
317}
318
319/**
320 *
321 */
322void CommSerial::v_RecvInit([[maybe_unused]] void *buf,
323 [[maybe_unused]] int count,
324 [[maybe_unused]] CommDataType dt,
325 [[maybe_unused]] int source,
326 [[maybe_unused]] CommRequestSharedPtr request,
327 [[maybe_unused]] int loc)
328{
329}
330
331/**
332 *
333 */
334void CommSerial::v_StartAll([[maybe_unused]] CommRequestSharedPtr request)
335{
336}
337
338/**
339 *
340 */
341void CommSerial::v_WaitAll([[maybe_unused]] CommRequestSharedPtr request)
342{
343}
344
345/**
346 *
347 */
349{
350 return std::shared_ptr<CommRequest>(new CommRequest);
351}
352
353/**
354 *
355 */
356void CommSerial::v_SplitComm([[maybe_unused]] int pRows,
357 [[maybe_unused]] int pColumns,
358 [[maybe_unused]] int pTime)
359{
360 ASSERTL0(false, "Cannot split a serial process.");
361}
362
363/**
364 *
365 */
367{
368 if (flag == 0)
369 {
370 // flag == 0 => get back MPI_COMM_NULL, return a null ptr instead.
371 return std::shared_ptr<Comm>();
372 }
373 else
374 {
375 // Return a real communicator
376 return shared_from_this();
377 }
378}
379
380} // namespace Nektar::LibUtilities
#define ASSERTL0(condition, msg)
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
void v_AllGather(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
void v_AlltoAllv(const void *sendbuf, const int *sendcounts, const int *senddispls, CommDataType sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, CommDataType recvtype) final
void v_SendInit(const void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
CommSharedPtr v_CommCreateIf(int flag) final
void v_Scatter(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
void v_Bcast(void *buffer, int count, CommDataType dt, int root) final
CommRequestSharedPtr v_CreateRequest(int num) final
void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
void v_AllGatherv(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, CommDataType recvtype) final
void v_DistGraphCreateAdjacent(int indegree, const int *sources, const int *sourceweights, int reorder) final
void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) final
void v_AlltoAll(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
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
void v_RecvInit(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
void v_SendRecv(const void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) final
void v_StartAll(CommRequestSharedPtr request) final
void v_Send(const void *buf, int count, CommDataType dt, int dest) final
CommSerial(int argc, char *argv[])
static std::string className
Name of class.
Definition CommSerial.h:62
void v_Isend(const void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
void v_Gather(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
void v_WaitAll(CommRequestSharedPtr request) final
void v_Irsend(const void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
void v_NeighborAlltoAllv(const void *sendbuf, const int *sendcounts, const int *senddispls, CommDataType sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, CommDataType recvtype) final
void v_Recv(void *buf, int count, CommDataType dt, int source) final
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
unsigned int CommDataType
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.