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 
60 {
61 }
62 
63 /**
64  *
65  */
67 {
68 #ifdef NEKTAR_USING_PETSC
69  PetscFinalize();
70 #endif
71 }
72 
73 /**
74  *
75  */
77 {
78  return 0;
79 }
80 
81 /**
82  *
83  */
85 {
86  return true;
87 }
88 
89 /**
90  *
91  */
93 {
94  return true;
95 }
96 
97 /**
98  *
99  */
101 {
102 }
103 
104 /**
105  *
106  */
108 {
109  return 0;
110 }
111 
112 /**
113  *
114  */
115 void CommSerial::v_Send(void *buf, int count, CommDataType dt, int dest)
116 {
117  boost::ignore_unused(buf, count, dt, dest);
118 }
119 
120 /**
121  *
122  */
123 void CommSerial::v_Recv(void *buf, int count, CommDataType dt, int source)
124 {
125  boost::ignore_unused(buf, count, dt, source);
126 }
127 
128 /**
129  *
130  */
131 void CommSerial::v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype,
132  int dest, void *recvbuf, int recvcount,
133  CommDataType recvtype, int source)
134 {
135  boost::ignore_unused(sendbuf, sendcount, sendtype, dest, recvbuf,
136  recvcount, recvtype, source);
137 }
138 
139 /**
140  *
141  */
142 void CommSerial::v_SendRecvReplace(void *buf, int count, CommDataType dt,
143  int pSendProc, int pRecvProc)
144 {
145  boost::ignore_unused(buf, count, dt, pSendProc, pRecvProc);
146 }
147 
148 /**
149  *
150  */
151 void CommSerial::v_AllReduce(void *buf, int count, CommDataType dt,
152  enum ReduceOperator pOp)
153 {
154  boost::ignore_unused(buf, count, dt, pOp);
155 }
156 
157 /**
158  *
159  */
160 void CommSerial::v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
161  void *recvbuf, int recvcount, CommDataType recvtype)
162 {
163  boost::ignore_unused(sendbuf, sendcount, sendtype, recvbuf, recvcount,
164  recvtype);
165 }
166 
167 /**
168  *
169  */
170 void CommSerial::v_AlltoAllv(void *sendbuf, int sendcounts[], int senddispls[],
171  CommDataType sendtype, void *recvbuf,
172  int recvcounts[], int rdispls[],
173  CommDataType recvtype)
174 {
175  boost::ignore_unused(sendbuf, sendcounts, senddispls, sendtype, recvbuf,
176  recvcounts, rdispls, recvtype);
177 }
178 
179 /**
180  *
181  */
182 void CommSerial::v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype,
183  void *recvbuf, int recvcount, CommDataType recvtype)
184 {
185  boost::ignore_unused(sendbuf, sendcount, sendtype, recvbuf, recvcount,
186  recvtype);
187 }
188 
189 void CommSerial::v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype,
190  void *recvbuf, int recvcounts[], int rdispls[],
191  CommDataType recvtype)
192 {
193  boost::ignore_unused(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
194  rdispls, recvtype);
195 }
196 
197 void CommSerial::v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[],
198  CommDataType recvtype)
199 {
200  boost::ignore_unused(recvbuf, recvcounts, rdispls, recvtype);
201 }
202 
203 void CommSerial::v_Bcast(void *buffer, int count, CommDataType dt, int root)
204 {
205  boost::ignore_unused(buffer, count, dt, root);
206 }
207 
209  const enum ReduceOperator pOp,
211 {
212  boost::ignore_unused(pData, pOp, ans);
213 }
214 
215 void CommSerial::v_Gather(void *sendbuf, int sendcount, CommDataType sendtype,
216  void *recvbuf, int recvcount, CommDataType recvtype,
217  int root)
218 {
219  boost::ignore_unused(recvcount, recvtype, root);
220  std::memcpy(recvbuf, sendbuf, sendcount * CommDataTypeGetSize(sendtype));
221 }
222 
223 void CommSerial::v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype,
224  void *recvbuf, int recvcount, CommDataType recvtype,
225  int root)
226 {
227  boost::ignore_unused(recvcount, recvtype, root);
228  std::memcpy(recvbuf, sendbuf, sendcount * CommDataTypeGetSize(sendtype));
229 }
230 /**
231  *
232  */
233 void CommSerial::v_SplitComm(int pRows, int pColumns)
234 {
235  boost::ignore_unused(pRows, pColumns);
236  ASSERTL0(false, "Cannot split a serial process.");
237 }
238 
239 /**
240  *
241  */
243 {
244  if (flag == 0)
245  {
246  // flag == 0 => get back MPI_COMM_NULL, return a null ptr instead.
247  return std::shared_ptr<Comm>();
248  }
249  else
250  {
251  // Return a real communicator
252  return shared_from_this();
253  }
254 
255 }
256 }
257 }
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc)
Definition: CommSerial.cpp:142
virtual void v_SplitComm(int pRows, int pColumns)
Definition: CommSerial.cpp:233
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, const enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans)
Definition: CommSerial.cpp:208
ReduceOperator
Type of operation to perform in AllReduce.
Definition: Comm.h:65
int CommDataTypeGetSize(CommDataType dt)
Return the size in bytes of a data type dt.
virtual bool v_TreatAsRankZero(void)
Definition: CommSerial.cpp:84
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)
Definition: CommSerial.cpp:189
std::string m_type
Type of communication.
Definition: Comm.h:149
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
array buffer
Definition: GsLib.hpp:61
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)
Definition: CommSerial.cpp:170
virtual bool v_IsSerial(void)
Definition: CommSerial.cpp:92
CommFactory & GetCommFactory()
virtual void v_Send(void *buf, int count, CommDataType dt, int dest)
Definition: CommSerial.cpp:115
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)
Definition: CommSerial.cpp:160
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
Definition: CommSerial.h:58
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)
Definition: CommSerial.cpp:215
double NekDouble
virtual CommSharedPtr v_CommCreateIf(int flag)
Definition: CommSerial.cpp:242
virtual void v_Recv(void *buf, int count, CommDataType dt, int source)
Definition: CommSerial.cpp:123
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root)
Definition: CommSerial.cpp:203
Base communications class.
Definition: Comm.h:81
CommSerial(int argc, char *argv[])
Definition: CommSerial.cpp:50
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp)
Definition: CommSerial.cpp:151
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source)
Definition: CommSerial.cpp:131
static std::string className
Name of class.
Definition: CommSerial.h:64
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)
Definition: CommSerial.cpp:182
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)
Definition: CommSerial.cpp:223
int m_size
Number of processes.
Definition: Comm.h:148