Nektar++
Comm.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Comm.h
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: Base communication class
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 #ifndef NEKTAR_LIB_UTILITIES_COMM_H
35 #define NEKTAR_LIB_UTILITIES_COMM_H
36 
37 #include <memory>
38 #include <type_traits>
39 #include <utility>
40 #include <vector>
41 
44 
48 
49 namespace Nektar
50 {
51 namespace LibUtilities
52 {
53 // Forward declarations
54 class Comm;
55 
56 /// Pointer to a Communicator object.
57 typedef std::shared_ptr<Comm> CommSharedPtr;
58 
59 /// Datatype of the NekFactory used to instantiate classes derived from
60 /// the EquationSystem class.
62 
64 
65 /// Type of operation to perform in AllReduce.
67 {
72 };
73 
74 const char *const ReduceOperatorMap[] = {"ReduceSum", "ReduceMax", "ReduceMin"};
75 
76 /// Class for communicator request type
78 {
79 public:
80  /// Default constructor
81  CommRequest() = default;
82  /// Default destructor
83  virtual ~CommRequest() = default;
84 };
85 
86 typedef std::shared_ptr<CommRequest> CommRequestSharedPtr;
87 
88 /// Base communications class
89 class Comm : public std::enable_shared_from_this<Comm>
90 {
91 public:
92  LIB_UTILITIES_EXPORT Comm(int narg, char *arg[]);
93  LIB_UTILITIES_EXPORT virtual ~Comm();
94 
95  LIB_UTILITIES_EXPORT inline void Finalise();
96 
97  /// Returns number of processes
98  LIB_UTILITIES_EXPORT inline int GetSize() const;
99  LIB_UTILITIES_EXPORT inline int GetRank();
100  LIB_UTILITIES_EXPORT inline const std::string &GetType() const;
101 
102  /// Block execution until all processes reach this point
103  LIB_UTILITIES_EXPORT inline void Block();
104 
105  /// Return the time in seconds
107 
108  template <class T> void Send(int pProc, T &pData);
109  template <class T> void Recv(int pProc, T &pData);
110  template <class T>
111  void SendRecv(int pSendProc, T &pSendData, int pRecvProc, T &pRecvData);
112  template <class T>
113  void SendRecvReplace(int pSendProc, int pRecvProc, T &pData);
114 
115  template <class T> void AllReduce(T &pData, enum ReduceOperator pOp);
116 
117  template <class T> void AlltoAll(T &pSendData, T &pRecvData);
118  template <class T1, class T2>
119  void AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap,
120  T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap);
121 
122  template <class T> void AllGather(T &pSendData, T &pRecvData);
123  template <class T>
124  void AllGatherv(T &pSendData, T &pRecvData,
125  Array<OneD, int> &pRecvDataSizeMap,
126  Array<OneD, int> &pRecvDataOffsetMap);
127  template <class T>
128  void AllGatherv(T &pRecvData, Array<OneD, int> &pRecvDataSizeMap,
129  Array<OneD, int> &pRecvDataOffsetMap);
130 
131  template <class T> void Bcast(T &pData, int pRoot);
132 
133  template <class T> void Exscan(T &pData, enum ReduceOperator pOp, T &ans);
134 
135  template <class T> T Gather(int rootProc, T &val);
136  template <class T> T Scatter(int rootProc, T &pData);
137 
138  template <class T>
139  void DistGraphCreateAdjacent(T &sources, T &sourceweights, int reorder);
140  template <class T1, class T2>
141  void NeighborAlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap,
142  T2 &pSendDataOffsetMap, T1 &pRecvData,
143  T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap);
144  template <class T>
145  void Irsend(int pProc, T &pData, int count,
146  const CommRequestSharedPtr &request, int loc);
147  template <class T>
148  void Isend(int pProc, T &pData, int count,
149  const CommRequestSharedPtr &request, int loc);
150  template <class T>
151  void SendInit(int pProc, T &pData, int count,
152  const CommRequestSharedPtr &request, int loc);
153  template <class T>
154  void Irecv(int pProc, T &pData, int count,
155  const CommRequestSharedPtr &request, int loc);
156  template <class T>
157  void RecvInit(int pProc, T &pData, int count,
158  const CommRequestSharedPtr &request, int loc);
159  inline void StartAll(const CommRequestSharedPtr &request);
160  inline void WaitAll(const CommRequestSharedPtr &request);
161  inline CommRequestSharedPtr CreateRequest(int num);
162 
164 
165  LIB_UTILITIES_EXPORT inline void SplitComm(int pRows, int pColumns,
166  int pTime = 1);
171 
173  LIB_UTILITIES_EXPORT inline bool IsSerial();
174  LIB_UTILITIES_EXPORT inline std::tuple<int, int, int> GetVersion();
176 
177  LIB_UTILITIES_EXPORT inline std::pair<CommSharedPtr, CommSharedPtr>
178  SplitCommNode();
179 
180 protected:
181  int m_size; ///< Number of processes
182  std::string m_type; ///< Type of communication
183  CommSharedPtr m_commRow; ///< Row communicator
184  CommSharedPtr m_commColumn; ///< Column communicator
187 
188  Comm();
189 
190  virtual void v_Finalise() = 0;
191  virtual int v_GetRank() = 0;
192  virtual void v_Block() = 0;
193  virtual NekDouble v_Wtime() = 0;
194  virtual void v_Send(void *buf, int count, CommDataType dt, int dest) = 0;
195  virtual void v_Recv(void *buf, int count, CommDataType dt, int source) = 0;
196  virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype,
197  int dest, void *recvbuf, int recvcount,
198  CommDataType recvtype, int source) = 0;
199  virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt,
200  int pSendProc, int pRecvProc) = 0;
201  virtual void v_AllReduce(void *buf, int count, CommDataType dt,
202  enum ReduceOperator pOp) = 0;
203  virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
204  void *recvbuf, int recvcount,
205  CommDataType recvtype) = 0;
206  virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[],
207  CommDataType sendtype, void *recvbuf,
208  int recvcounts[], int rdispls[],
209  CommDataType recvtype) = 0;
210  virtual void v_AllGather(void *sendbuf, int sendcount,
211  CommDataType sendtype, void *recvbuf,
212  int recvcount, CommDataType recvtype) = 0;
213  virtual void v_AllGatherv(void *sendbuf, int sendcount,
214  CommDataType sendtype, void *recvbuf,
215  int recvcounts[], int rdispls[],
216  CommDataType recvtype) = 0;
217  virtual void v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[],
218  CommDataType recvtype) = 0;
219  virtual void v_Bcast(void *buffer, int count, CommDataType dt,
220  int root) = 0;
221 
223  enum ReduceOperator pOp,
225 
226  virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype,
227  void *recvbuf, int recvcount, CommDataType recvtype,
228  int root) = 0;
229  virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype,
230  void *recvbuf, int recvcount, CommDataType recvtype,
231  int root) = 0;
232 
233  virtual CommSharedPtr v_CommCreateIf(int flag) = 0;
234 
235  virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[],
236  const int sourceweights[],
237  int reorder) = 0;
238 
239  virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[],
240  int sdispls[], CommDataType sendtype,
241  void *recvbuf, int recvcounts[],
242  int rdispls[], CommDataType recvtype) = 0;
243 
244  virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest,
245  CommRequestSharedPtr request, int loc) = 0;
246  virtual void v_Isend(void *buf, int count, CommDataType dt, int dest,
247  CommRequestSharedPtr request, int loc) = 0;
248  virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest,
249  CommRequestSharedPtr request, int loc) = 0;
250  virtual void v_Irecv(void *buf, int count, CommDataType dt, int source,
251  CommRequestSharedPtr request, int loc) = 0;
252  virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source,
253  CommRequestSharedPtr request, int loc) = 0;
254  virtual void v_StartAll(CommRequestSharedPtr request) = 0;
255  virtual void v_WaitAll(CommRequestSharedPtr request) = 0;
256  virtual CommRequestSharedPtr v_CreateRequest(int num) = 0;
257 
258  virtual void v_SplitComm(int pRows, int pColumns, int pTime) = 0;
259  virtual bool v_TreatAsRankZero() = 0;
260  virtual bool v_IsSerial() = 0;
261  virtual std::tuple<int, int, int> v_GetVersion() = 0;
262 
264  LIB_UTILITIES_EXPORT virtual std::pair<CommSharedPtr, CommSharedPtr>
265  v_SplitCommNode();
266 };
267 
268 /**
269  *
270  */
271 inline void Comm::Finalise()
272 {
273  v_Finalise();
274 }
275 
276 /**
277  *
278  */
279 inline int Comm::GetSize() const
280 {
281  return m_size;
282 }
283 
284 /**
285  *
286  */
287 inline int Comm::GetRank()
288 {
289  return v_GetRank();
290 }
291 
292 /**
293  *
294  */
295 inline const std::string &Comm::GetType() const
296 {
297  return m_type;
298 }
299 
300 /**
301  *
302  */
303 inline void Comm::Block()
304 {
305  v_Block();
306 }
307 
308 /**
309  *
310  */
311 inline double Comm::Wtime()
312 {
313  return v_Wtime();
314 }
315 
316 template <class T> void Comm::Send(int pProc, T &pData)
317 {
321 }
322 
323 template <class T> void Comm::Recv(int pProc, T &pData)
324 {
328 }
329 
330 /**
331  *
332  */
333 template <class T>
334 void Comm::SendRecv(int pSendProc, T &pSendData, int pRecvProc, T &pRecvData)
335 {
342 }
343 
344 /**
345  *
346  */
347 template <class T>
348 void Comm::SendRecvReplace(int pSendProc, int pRecvProc, T &pData)
349 {
353  pRecvProc);
354 }
355 
356 /**
357  *
358  */
359 template <class T> void Comm::AllReduce(T &pData, enum ReduceOperator pOp)
360 {
364 }
365 
366 template <class T> void Comm::AlltoAll(T &pSendData, T &pRecvData)
367 {
368  static_assert(CommDataTypeTraits<T>::IsVector,
369  "AlltoAll only valid with Array or vector arguments.");
370  int sendSize = CommDataTypeTraits<T>::GetCount(pSendData);
371  int recvSize = CommDataTypeTraits<T>::GetCount(pRecvData);
372  ASSERTL0(sendSize == recvSize,
373  "Send and Recv arrays have incompatible sizes in AlltoAll");
374 
375  int count = sendSize / GetSize();
376  ASSERTL0(count * GetSize() == sendSize,
377  "Array size incompatible with size of communicator");
378 
381  CommDataTypeTraits<T>::GetPointer(pRecvData), count,
383 }
384 
385 /**
386  *
387  */
388 template <class T1, class T2>
389 void Comm::AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap,
390  T2 &pSendDataOffsetMap, T1 &pRecvData,
391  T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
392 {
393  static_assert(CommDataTypeTraits<T1>::IsVector,
394  "AlltoAllv only valid with Array or vector arguments.");
395  static_assert(std::is_same<T2, std::vector<int>>::value ||
396  std::is_same<T2, Array<OneD, int>>::value,
397  "Alltoallv size and offset maps should be integer vectors.");
399  (int *)CommDataTypeTraits<T2>::GetPointer(pSendDataSizeMap),
400  (int *)CommDataTypeTraits<T2>::GetPointer(pSendDataOffsetMap),
403  (int *)CommDataTypeTraits<T2>::GetPointer(pRecvDataSizeMap),
404  (int *)CommDataTypeTraits<T2>::GetPointer(pRecvDataOffsetMap),
406 }
407 
408 template <class T> void Comm::AllGather(T &pSendData, T &pRecvData)
409 {
410  BOOST_STATIC_ASSERT_MSG(
412  "AllGather only valid with Array or vector arguments.");
413 
414  int sendSize = CommDataTypeTraits<T>::GetCount(pSendData);
415  int recvSize = sendSize;
416 
417  pRecvData = T(recvSize * GetSize());
418 
419  v_AllGather(CommDataTypeTraits<T>::GetPointer(pSendData), sendSize,
421  CommDataTypeTraits<T>::GetPointer(pRecvData), recvSize,
423 }
424 
425 /**
426  *
427  */
428 template <class T>
429 void Comm::AllGatherv(T &pSendData, T &pRecvData,
430  Array<OneD, int> &pRecvDataSizeMap,
431  Array<OneD, int> &pRecvDataOffsetMap)
432 {
433  BOOST_STATIC_ASSERT_MSG(
435  "AllGatherv only valid with Array or vector arguments.");
436 
437  int sendSize = CommDataTypeTraits<T>::GetCount(pSendData);
438 
439  v_AllGatherv(CommDataTypeTraits<T>::GetPointer(pSendData), sendSize,
442  pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
444 }
445 
446 /**
447  *
448  */
449 template <class T>
450 void Comm::AllGatherv(T &pRecvData, Array<OneD, int> &pRecvDataSizeMap,
451  Array<OneD, int> &pRecvDataOffsetMap)
452 {
453  BOOST_STATIC_ASSERT_MSG(
455  "AllGatherv only valid with Array or vector arguments.");
456 
458  pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
460 }
461 
462 /**
463  *
464  */
465 template <class T> void Comm::Bcast(T &pData, int pRoot)
466 {
470 }
471 
472 template <class T>
473 void Comm::Exscan(T &pData, const enum ReduceOperator pOp, T &ans)
474 {
477  "Input and output array sizes don't match");
482 }
483 
484 /**
485  * Concatenate all the input arrays, in rank order, onto the process with rank
486  * == rootProc
487  */
488 template <class T> T Comm::Gather(const int rootProc, T &val)
489 {
490  static_assert(CommDataTypeTraits<T>::IsVector,
491  "Gather only valid with Array or vector arguments.");
492  bool amRoot = (GetRank() == rootProc);
493  unsigned nEl = CommDataTypeTraits<T>::GetCount(val);
494 
495  unsigned nOut = amRoot ? GetSize() * nEl : 0;
496  T ans(nOut);
497  void *recvbuf = amRoot ? CommDataTypeTraits<T>::GetPointer(ans) : NULL;
498 
500  CommDataTypeTraits<T>::GetDataType(), recvbuf, nEl,
502  return ans;
503 }
504 /**
505  * Scatter pData across ranks in chunks of len(pData)/num_ranks
506  */
507 template <class T> T Comm::Scatter(const int rootProc, T &pData)
508 {
509  static_assert(CommDataTypeTraits<T>::IsVector,
510  "Scatter only valid with Array or vector arguments.");
511 
512  bool amRoot = (GetRank() == rootProc);
513  unsigned nEl = CommDataTypeTraits<T>::GetCount(pData) / GetSize();
514 
515  void *sendbuf = amRoot ? CommDataTypeTraits<T>::GetPointer(pData) : NULL;
516  T ans(nEl);
517 
521  return ans;
522 }
523 
524 /**
525  * This replaces the current MPI communicator with a new one that also holds
526  * the distributed graph topology information. If reordering is enabled using
527  * this might break code where process/rank numbers are assumed to remain
528  * constant. This also assumes that the graph is bi-directional, so all
529  * sources are also destinations with equal weighting.
530  *
531  * @param sources Ranks of processes for which the calling process is the
532  * destination/source
533  * @param sourceweights Weights of the corresponding edges into the calling
534  * process
535  * @param reorder Ranks may be reordered (true) or not (false)
536  */
537 template <class T>
538 void Comm::DistGraphCreateAdjacent(T &sources, T &sourceweights, int reorder)
539 {
540  static_assert(
542  "DistGraphCreateAdjacent only valid with Array or vector arguments.");
543 
545  CommDataTypeTraits<T>::GetCount(sourceweights),
546  "Sources and weights array sizes don't match");
547 
548  int indegree = CommDataTypeTraits<T>::GetCount(sources);
549 
551  indegree, (const int *)CommDataTypeTraits<T>::GetPointer(sources),
552  (const int *)CommDataTypeTraits<T>::GetPointer(sourceweights), reorder);
553 }
554 
555 /**
556  * Sends data to neighboring processes in a virtual topology communicator. All
557  * processes send different amounts of data to, and receive different amounts
558  * of data from, all neighbors
559  *
560  * @param pSendData Array/vector to send to neighbors
561  * @param pSendDataSizeMap Array/vector where entry i specifies the number
562  * of elements to send to neighbor i
563  * @param pSendDataOffsetMap Array/vector where entry i specifies the
564  * displacement (offset from pSendData) from which to
565  * send data to neighbor i
566  * @param pRecvData Array/vector to place incoming data in to
567  * @param pRecvDataSizeMap Array/vector where entry i specifies the number
568  * of elements to receive from neighbor i
569  * @param pRecvDataOffsetMap Array/vector where entry i specifies the
570  * displacement (offset from pRecvData) from which to
571  * receive data from neighbor i
572  */
573 template <class T1, class T2>
574 void Comm::NeighborAlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap,
575  T2 &pSendDataOffsetMap, T1 &pRecvData,
576  T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
577 {
578  static_assert(
580  "NeighbourAlltoAllv only valid with Array or vector arguments.");
581  static_assert(
582  std::is_same<T2, std::vector<int>>::value ||
583  std::is_same<T2, Array<OneD, int>>::value,
584  "NeighborAllToAllv size and offset maps should be integer vectors.");
587  (int *)CommDataTypeTraits<T2>::GetPointer(pSendDataSizeMap),
588  (int *)CommDataTypeTraits<T2>::GetPointer(pSendDataOffsetMap),
591  (int *)CommDataTypeTraits<T2>::GetPointer(pRecvDataSizeMap),
592  (int *)CommDataTypeTraits<T2>::GetPointer(pRecvDataOffsetMap),
594 }
595 
596 /**
597  * Starts a ready-mode nonblocking send
598  *
599  * @param pProc Rank of destination
600  * @param pData Array/vector to send
601  * @param count Number of elements to send in pData
602  * @param request Communication request object
603  * @param loc Location in request to use
604  */
605 template <class T>
606 void Comm::Irsend(int pProc, T &pData, int count,
607  const CommRequestSharedPtr &request, int loc)
608 {
610  CommDataTypeTraits<T>::GetDataType(), pProc, request, loc);
611 }
612 
613 /**
614  * Starts a nonblocking send
615  *
616  * @param pProc Rank of destination
617  * @param pData Array/vector to send
618  * @param count Number of elements to send in pData
619  * @param request Communication request object
620  * @param loc Location in request to use
621  */
622 template <class T>
623 void Comm::Isend(int pProc, T &pData, int count,
624  const CommRequestSharedPtr &request, int loc)
625 {
627  CommDataTypeTraits<T>::GetDataType(), pProc, request, loc);
628 }
629 
630 /**
631  * Creates a persistent request for a send
632  *
633  * @param pProc Rank of destination
634  * @param pData Array/vector to send
635  * @param count Number of elements to send in pData
636  * @param request Communication request object
637  * @param loc Location in request to use
638  */
639 template <class T>
640 void Comm::SendInit(int pProc, T &pData, int count,
641  const CommRequestSharedPtr &request, int loc)
642 {
644  CommDataTypeTraits<T>::GetDataType(), pProc, request, loc);
645 }
646 
647 /**
648  * Begins a nonblocking receive
649  *
650  * @param pProc Rank of source
651  * @param pData Array/vector to place incoming data in to
652  * @param count Number of elements to receive in to pData
653  * @param request Communication request object
654  * @param loc Location in request to use
655  */
656 template <class T>
657 void Comm::Irecv(int pProc, T &pData, int count,
658  const CommRequestSharedPtr &request, int loc)
659 {
661  CommDataTypeTraits<T>::GetDataType(), pProc, request, loc);
662 }
663 
664 /**
665  * Create a persistent request for a receive
666  *
667  * @param pProc Rank of source
668  * @param pData Array/vector to place incoming data in to
669  * @param count Number of elements to receive in to pData
670  * @param request Communication request object
671  * @param loc Location in request to use
672  */
673 template <class T>
674 void Comm::RecvInit(int pProc, T &pData, int count,
675  const CommRequestSharedPtr &request, int loc)
676 {
678  CommDataTypeTraits<T>::GetDataType(), pProc, request, loc);
679 }
680 
681 /**
682  * Starts a collection of persistent requests
683  *
684  * @param request Communication request object
685  */
686 inline void Comm::StartAll(const CommRequestSharedPtr &request)
687 {
688  v_StartAll(request);
689 }
690 
691 /**
692  * Waits for all CommRequests in the request object to complete.
693  *
694  * @param request Communication request object
695  */
696 inline void Comm::WaitAll(const CommRequestSharedPtr &request)
697 {
698  v_WaitAll(request);
699 }
700 
701 /**
702  * Creates a number of CommRequests.
703  *
704  * @param num Number of requests to generate in the communication request object
705  *
706  * @return Communication request object
707  */
709 {
710  return v_CreateRequest(num);
711 }
712 
713 /**
714  * @brief If the flag is non-zero create a new communicator.
715  */
717 {
718  return v_CommCreateIf(flag);
719 }
720 
721 /**
722  * @brief Splits this communicator into a grid of size pRows*pColumns
723  * and creates row and column communicators. By default the communicator
724  * is a single row.
725  */
726 inline void Comm::SplitComm(int pRows, int pColumns, int pTime)
727 {
728  v_SplitComm(pRows, pColumns, pTime);
729 }
730 
731 /**
732  * @brief Retrieve the row communicator to which this process belongs.
733  */
735 {
736  if (!m_commRow.get())
737  {
738  return shared_from_this();
739  }
740  else
741  {
742  return m_commRow;
743  }
744 }
745 
746 /**
747  * @brief Retrieve the column communicator to which this process
748  * belongs.
749  */
751 {
752  if (!m_commColumn.get())
753  {
754  return shared_from_this();
755  }
756  else
757  {
758  return m_commColumn;
759  }
760 }
761 
762 /**
763  * @brief Retrieve the time communicator to which this process
764  * belongs.
765  */
767 {
768  if (!m_commTime.get())
769  {
770  return shared_from_this();
771  }
772  else
773  {
774  return m_commTime;
775  }
776 }
777 
778 /**
779  * @brief Retrieve the space communicator to which this process
780  * belongs.
781  */
783 {
784  if (!m_commSpace.get())
785  {
786  return shared_from_this();
787  }
788  else
789  {
790  return m_commSpace;
791  }
792 }
793 
795 {
796  return v_TreatAsRankZero();
797 }
798 
799 inline bool Comm::IsSerial()
800 {
801  return v_IsSerial();
802 }
803 
804 /**
805  * @return tuple of {major, minor, patch} version numbers
806  */
807 inline std::tuple<int, int, int> Comm::GetVersion()
808 {
809  return v_GetVersion();
810 }
811 
813 {
814  return v_RemoveExistingFiles();
815 }
816 
817 std::pair<CommSharedPtr, CommSharedPtr> Comm::SplitCommNode()
818 {
819  return v_SplitCommNode();
820 }
821 
822 } // namespace LibUtilities
823 } // namespace Nektar
824 
825 #endif
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define LIB_UTILITIES_EXPORT
Base communications class.
Definition: Comm.h:90
void SendRecv(int pSendProc, T &pSendData, int pRecvProc, T &pRecvData)
Definition: Comm.h:334
void AllGather(T &pSendData, T &pRecvData)
Definition: Comm.h:408
virtual CommSharedPtr v_CommCreateIf(int flag)=0
void AlltoAll(T &pSendData, T &pRecvData)
Definition: Comm.h:366
CommSharedPtr GetSpaceComm()
Retrieve the space communicator to which this process belongs.
Definition: Comm.h:782
void Isend(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
Definition: Comm.h:623
virtual std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode()
CommSharedPtr m_commColumn
Column communicator.
Definition: Comm.h:184
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
CommSharedPtr CommCreateIf(int flag)
If the flag is non-zero create a new communicator.
Definition: Comm.h:716
CommSharedPtr GetColumnComm()
Retrieve the column communicator to which this process belongs.
Definition: Comm.h:750
bool RemoveExistingFiles()
Definition: Comm.h:812
T Gather(int rootProc, T &val)
Definition: Comm.h:488
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans)=0
void Block()
Block execution until all processes reach this point.
Definition: Comm.h:303
CommSharedPtr GetRowComm()
Retrieve the row communicator to which this process belongs.
Definition: Comm.h:734
CommRequestSharedPtr CreateRequest(int num)
Definition: Comm.h:708
NekDouble Wtime()
Return the time in seconds.
Definition: Comm.h:311
void StartAll(const CommRequestSharedPtr &request)
Definition: Comm.h:686
virtual void v_Isend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc)=0
virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
void Exscan(T &pData, enum ReduceOperator pOp, T &ans)
Definition: Comm.h:473
CommSharedPtr m_commRow
Row communicator.
Definition: Comm.h:183
const std::string & GetType() const
Definition: Comm.h:295
void SendRecvReplace(int pSendProc, int pRecvProc, T &pData)
Definition: Comm.h:348
virtual void v_WaitAll(CommRequestSharedPtr request)=0
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source)=0
void Bcast(T &pData, int pRoot)
Definition: Comm.h:465
int GetSize() const
Returns number of processes.
Definition: Comm.h:279
void SendInit(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
Definition: Comm.h:640
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)=0
void SplitComm(int pRows, int pColumns, int pTime=1)
Splits this communicator into a grid of size pRows*pColumns and creates row and column communicators....
Definition: Comm.h:726
virtual void v_Recv(void *buf, int count, CommDataType dt, int source)=0
virtual void v_Send(void *buf, int count, CommDataType dt, int dest)=0
virtual int v_GetRank()=0
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)=0
CommSharedPtr m_commTime
Definition: Comm.h:185
void AllGatherv(T &pSendData, T &pRecvData, Array< OneD, int > &pRecvDataSizeMap, Array< OneD, int > &pRecvDataOffsetMap)
Definition: Comm.h:429
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc)=0
void Send(int pProc, T &pData)
Definition: Comm.h:316
int m_size
Number of processes.
Definition: Comm.h:181
std::string m_type
Type of communication.
Definition: Comm.h:182
void Recv(int pProc, T &pData)
Definition: Comm.h:323
void WaitAll(const CommRequestSharedPtr &request)
Definition: Comm.h:696
virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc)=0
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp)=0
virtual NekDouble v_Wtime()=0
virtual CommRequestSharedPtr v_CreateRequest(int num)=0
void AllReduce(T &pData, enum ReduceOperator pOp)
Definition: Comm.h:359
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
std::pair< CommSharedPtr, CommSharedPtr > SplitCommNode()
Definition: Comm.h:817
virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc)=0
virtual std::tuple< int, int, int > v_GetVersion()=0
void RecvInit(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
Definition: Comm.h:674
virtual void v_Block()=0
std::tuple< int, int, int > GetVersion()
Definition: Comm.h:807
void Irecv(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
Definition: Comm.h:657
virtual void v_Finalise()=0
CommSharedPtr GetTimeComm()
Retrieve the time communicator to which this process belongs.
Definition: Comm.h:766
void AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap, T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
Definition: Comm.h:389
virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[], const int sourceweights[], int reorder)=0
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root)=0
void DistGraphCreateAdjacent(T &sources, T &sourceweights, int reorder)
Definition: Comm.h:538
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
virtual void v_StartAll(CommRequestSharedPtr request)=0
void Irsend(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
Definition: Comm.h:606
T Scatter(int rootProc, T &pData)
Definition: Comm.h:507
virtual bool v_TreatAsRankZero()=0
virtual void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc)=0
virtual bool v_IsSerial()=0
CommSharedPtr m_commSpace
Definition: Comm.h:186
virtual void v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc)=0
void NeighborAlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap, T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
Definition: Comm.h:574
virtual void v_SplitComm(int pRows, int pColumns, int pTime)=0
Class for communicator request type.
Definition: Comm.h:78
virtual ~CommRequest()=default
Default destructor.
CommRequest()=default
Default constructor.
Provides a generic Factory class.
Definition: NekFactory.hpp:105
array buffer
Definition: GsLib.hpp:83
LibUtilities::NekFactory< std::string, Comm, int, char ** > CommFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class.
Definition: Comm.h:61
const char *const ReduceOperatorMap[]
Definition: Comm.h:74
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
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble