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 SendInit(int pProc, T &pData, int count,
149  const CommRequestSharedPtr &request, int loc);
150  template <class T>
151  void Irecv(int pProc, T &pData, int count,
152  const CommRequestSharedPtr &request, int loc);
153  template <class T>
154  void RecvInit(int pProc, T &pData, int count,
155  const CommRequestSharedPtr &request, int loc);
156  inline void StartAll(const CommRequestSharedPtr &request);
157  inline void WaitAll(const CommRequestSharedPtr &request);
158  inline CommRequestSharedPtr CreateRequest(int num);
159 
161 
162  LIB_UTILITIES_EXPORT inline void SplitComm(int pRows, int pColumns);
165 
167  LIB_UTILITIES_EXPORT inline bool IsSerial();
168  LIB_UTILITIES_EXPORT inline std::tuple<int, int, int> GetVersion();
170 
171  LIB_UTILITIES_EXPORT inline std::pair<CommSharedPtr, CommSharedPtr>
172  SplitCommNode();
173 
174 protected:
175  int m_size; ///< Number of processes
176  std::string m_type; ///< Type of communication
177  CommSharedPtr m_commRow; ///< Row communicator
178  CommSharedPtr m_commColumn; ///< Column communicator
179 
180  Comm();
181 
182  virtual void v_Finalise() = 0;
183  virtual int v_GetRank() = 0;
184  virtual void v_Block() = 0;
185  virtual NekDouble v_Wtime() = 0;
186  virtual void v_Send(void *buf, int count, CommDataType dt, int dest) = 0;
187  virtual void v_Recv(void *buf, int count, CommDataType dt, int source) = 0;
188  virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype,
189  int dest, void *recvbuf, int recvcount,
190  CommDataType recvtype, int source) = 0;
191  virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt,
192  int pSendProc, int pRecvProc) = 0;
193  virtual void v_AllReduce(void *buf, int count, CommDataType dt,
194  enum ReduceOperator pOp) = 0;
195  virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
196  void *recvbuf, int recvcount,
197  CommDataType recvtype) = 0;
198  virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[],
199  CommDataType sendtype, void *recvbuf,
200  int recvcounts[], int rdispls[],
201  CommDataType recvtype) = 0;
202  virtual void v_AllGather(void *sendbuf, int sendcount,
203  CommDataType sendtype, void *recvbuf,
204  int recvcount, CommDataType recvtype) = 0;
205  virtual void v_AllGatherv(void *sendbuf, int sendcount,
206  CommDataType sendtype, void *recvbuf,
207  int recvcounts[], int rdispls[],
208  CommDataType recvtype) = 0;
209  virtual void v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[],
210  CommDataType recvtype) = 0;
211  virtual void v_Bcast(void *buffer, int count, CommDataType dt,
212  int root) = 0;
213 
215  enum ReduceOperator pOp,
217 
218  virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype,
219  void *recvbuf, int recvcount, CommDataType recvtype,
220  int root) = 0;
221  virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype,
222  void *recvbuf, int recvcount, CommDataType recvtype,
223  int root) = 0;
224 
225  virtual CommSharedPtr v_CommCreateIf(int flag) = 0;
226 
227  virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[],
228  const int sourceweights[],
229  int reorder) = 0;
230 
231  virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[],
232  int sdispls[], CommDataType sendtype,
233  void *recvbuf, int recvcounts[],
234  int rdispls[], CommDataType recvtype) = 0;
235 
236  virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest,
237  CommRequestSharedPtr request, int loc) = 0;
238  virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest,
239  CommRequestSharedPtr request, int loc) = 0;
240  virtual void v_Irecv(void *buf, int count, CommDataType dt, int source,
241  CommRequestSharedPtr request, int loc) = 0;
242  virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source,
243  CommRequestSharedPtr request, int loc) = 0;
244  virtual void v_StartAll(CommRequestSharedPtr request) = 0;
245  virtual void v_WaitAll(CommRequestSharedPtr request) = 0;
246  virtual CommRequestSharedPtr v_CreateRequest(int num) = 0;
247 
248  virtual void v_SplitComm(int pRows, int pColumns) = 0;
249  virtual bool v_TreatAsRankZero() = 0;
250  virtual bool v_IsSerial() = 0;
251  virtual std::tuple<int, int, int> v_GetVersion() = 0;
252 
254  LIB_UTILITIES_EXPORT virtual std::pair<CommSharedPtr, CommSharedPtr>
255  v_SplitCommNode();
256 };
257 
258 /**
259  *
260  */
261 inline void Comm::Finalise()
262 {
263  v_Finalise();
264 }
265 
266 /**
267  *
268  */
269 inline int Comm::GetSize() const
270 {
271  return m_size;
272 }
273 
274 /**
275  *
276  */
277 inline int Comm::GetRank()
278 {
279  return v_GetRank();
280 }
281 
282 /**
283  *
284  */
285 inline const std::string &Comm::GetType() const
286 {
287  return m_type;
288 }
289 
290 /**
291  *
292  */
293 inline void Comm::Block()
294 {
295  v_Block();
296 }
297 
298 /**
299  *
300  */
301 inline double Comm::Wtime()
302 {
303  return v_Wtime();
304 }
305 
306 template <class T> void Comm::Send(int pProc, T &pData)
307 {
311 }
312 
313 template <class T> void Comm::Recv(int pProc, T &pData)
314 {
318 }
319 
320 /**
321  *
322  */
323 template <class T>
324 void Comm::SendRecv(int pSendProc, T &pSendData, int pRecvProc, T &pRecvData)
325 {
332 }
333 
334 /**
335  *
336  */
337 template <class T>
338 void Comm::SendRecvReplace(int pSendProc, int pRecvProc, T &pData)
339 {
343  pRecvProc);
344 }
345 
346 /**
347  *
348  */
349 template <class T> void Comm::AllReduce(T &pData, enum ReduceOperator pOp)
350 {
354 }
355 
356 template <class T> void Comm::AlltoAll(T &pSendData, T &pRecvData)
357 {
358  static_assert(CommDataTypeTraits<T>::IsVector,
359  "AlltoAll only valid with Array or vector arguments.");
360  int sendSize = CommDataTypeTraits<T>::GetCount(pSendData);
361  int recvSize = CommDataTypeTraits<T>::GetCount(pRecvData);
362  ASSERTL0(sendSize == recvSize,
363  "Send and Recv arrays have incompatible sizes in AlltoAll");
364 
365  int count = sendSize / GetSize();
366  ASSERTL0(count * GetSize() == sendSize,
367  "Array size incompatible with size of communicator");
368 
371  CommDataTypeTraits<T>::GetPointer(pRecvData), count,
373 }
374 
375 /**
376  *
377  */
378 template <class T1, class T2>
379 void Comm::AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap,
380  T2 &pSendDataOffsetMap, T1 &pRecvData,
381  T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
382 {
383  static_assert(CommDataTypeTraits<T1>::IsVector,
384  "AlltoAllv only valid with Array or vector arguments.");
385  static_assert(std::is_same<T2, std::vector<int>>::value ||
386  std::is_same<T2, Array<OneD, int>>::value,
387  "Alltoallv size and offset maps should be integer vectors.");
389  (int *)CommDataTypeTraits<T2>::GetPointer(pSendDataSizeMap),
390  (int *)CommDataTypeTraits<T2>::GetPointer(pSendDataOffsetMap),
393  (int *)CommDataTypeTraits<T2>::GetPointer(pRecvDataSizeMap),
394  (int *)CommDataTypeTraits<T2>::GetPointer(pRecvDataOffsetMap),
396 }
397 
398 template <class T> void Comm::AllGather(T &pSendData, T &pRecvData)
399 {
400  BOOST_STATIC_ASSERT_MSG(
402  "AllGather only valid with Array or vector arguments.");
403 
404  int sendSize = CommDataTypeTraits<T>::GetCount(pSendData);
405  int recvSize = sendSize;
406 
407  pRecvData = T(recvSize * GetSize());
408 
409  v_AllGather(CommDataTypeTraits<T>::GetPointer(pSendData), sendSize,
411  CommDataTypeTraits<T>::GetPointer(pRecvData), recvSize,
413 }
414 
415 /**
416  *
417  */
418 template <class T>
419 void Comm::AllGatherv(T &pSendData, T &pRecvData,
420  Array<OneD, int> &pRecvDataSizeMap,
421  Array<OneD, int> &pRecvDataOffsetMap)
422 {
423  BOOST_STATIC_ASSERT_MSG(
425  "AllGatherv only valid with Array or vector arguments.");
426 
427  int sendSize = CommDataTypeTraits<T>::GetCount(pSendData);
428 
429  v_AllGatherv(CommDataTypeTraits<T>::GetPointer(pSendData), sendSize,
432  pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
434 }
435 
436 /**
437  *
438  */
439 template <class T>
440 void Comm::AllGatherv(T &pRecvData, Array<OneD, int> &pRecvDataSizeMap,
441  Array<OneD, int> &pRecvDataOffsetMap)
442 {
443  BOOST_STATIC_ASSERT_MSG(
445  "AllGatherv only valid with Array or vector arguments.");
446 
448  pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
450 }
451 
452 /**
453  *
454  */
455 template <class T> void Comm::Bcast(T &pData, int pRoot)
456 {
460 }
461 
462 template <class T>
463 void Comm::Exscan(T &pData, const enum ReduceOperator pOp, T &ans)
464 {
467  "Input and output array sizes don't match");
472 }
473 
474 /**
475  * Concatenate all the input arrays, in rank order, onto the process with rank
476  * == rootProc
477  */
478 template <class T> T Comm::Gather(const int rootProc, T &val)
479 {
480  static_assert(CommDataTypeTraits<T>::IsVector,
481  "Gather only valid with Array or vector arguments.");
482  bool amRoot = (GetRank() == rootProc);
483  unsigned nEl = CommDataTypeTraits<T>::GetCount(val);
484 
485  unsigned nOut = amRoot ? GetSize() * nEl : 0;
486  T ans(nOut);
487  void *recvbuf = amRoot ? CommDataTypeTraits<T>::GetPointer(ans) : NULL;
488 
490  CommDataTypeTraits<T>::GetDataType(), recvbuf, nEl,
492  return ans;
493 }
494 /**
495  * Scatter pData across ranks in chunks of len(pData)/num_ranks
496  */
497 template <class T> T Comm::Scatter(const int rootProc, T &pData)
498 {
499  static_assert(CommDataTypeTraits<T>::IsVector,
500  "Scatter only valid with Array or vector arguments.");
501 
502  bool amRoot = (GetRank() == rootProc);
503  unsigned nEl = CommDataTypeTraits<T>::GetCount(pData) / GetSize();
504 
505  void *sendbuf = amRoot ? CommDataTypeTraits<T>::GetPointer(pData) : NULL;
506  T ans(nEl);
507 
511  return ans;
512 }
513 
514 /**
515  * This replaces the current MPI communicator with a new one that also holds
516  * the distributed graph topology information. If reordering is enabled using
517  * this might break code where process/rank numbers are assumed to remain
518  * constant. This also assumes that the graph is bi-directional, so all
519  * sources are also destinations with equal weighting.
520  *
521  * @param sources Ranks of processes for which the calling process is the
522  * destination/source
523  * @param sourceweights Weights of the corresponding edges into the calling
524  * process
525  * @param reorder Ranks may be reordered (true) or not (false)
526  */
527 template <class T>
528 void Comm::DistGraphCreateAdjacent(T &sources, T &sourceweights, int reorder)
529 {
530  static_assert(
532  "DistGraphCreateAdjacent only valid with Array or vector arguments.");
533 
535  CommDataTypeTraits<T>::GetCount(sourceweights),
536  "Sources and weights array sizes don't match");
537 
538  int indegree = CommDataTypeTraits<T>::GetCount(sources);
539 
541  indegree, (const int *)CommDataTypeTraits<T>::GetPointer(sources),
542  (const int *)CommDataTypeTraits<T>::GetPointer(sourceweights), reorder);
543 }
544 
545 /**
546  * Sends data to neighboring processes in a virtual topology communicator. All
547  * processes send different amounts of data to, and receive different amounts
548  * of data from, all neighbors
549  *
550  * @param pSendData Array/vector to send to neighbors
551  * @param pSendDataSizeMap Array/vector where entry i specifies the number
552  * of elements to send to neighbor i
553  * @param pSendDataOffsetMap Array/vector where entry i specifies the
554  * displacement (offset from pSendData) from which to
555  * send data to neighbor i
556  * @param pRecvData Array/vector to place incoming data in to
557  * @param pRecvDataSizeMap Array/vector where entry i specifies the number
558  * of elements to receive from neighbor i
559  * @param pRecvDataOffsetMap Array/vector where entry i specifies the
560  * displacement (offset from pRecvData) from which to
561  * receive data from neighbor i
562  */
563 template <class T1, class T2>
564 void Comm::NeighborAlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap,
565  T2 &pSendDataOffsetMap, T1 &pRecvData,
566  T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
567 {
568  static_assert(
570  "NeighbourAlltoAllv only valid with Array or vector arguments.");
571  static_assert(
572  std::is_same<T2, std::vector<int>>::value ||
573  std::is_same<T2, Array<OneD, int>>::value,
574  "NeighborAllToAllv size and offset maps should be integer vectors.");
577  (int *)CommDataTypeTraits<T2>::GetPointer(pSendDataSizeMap),
578  (int *)CommDataTypeTraits<T2>::GetPointer(pSendDataOffsetMap),
581  (int *)CommDataTypeTraits<T2>::GetPointer(pRecvDataSizeMap),
582  (int *)CommDataTypeTraits<T2>::GetPointer(pRecvDataOffsetMap),
584 }
585 
586 /**
587  * Starts a ready-mode nonblocking send
588  *
589  * @param pProc Rank of destination
590  * @param pData Array/vector to send
591  * @param count Number of elements to send in pData
592  * @param request Communication request object
593  * @param loc Location in request to use
594  */
595 template <class T>
596 void Comm::Irsend(int pProc, T &pData, int count,
597  const CommRequestSharedPtr &request, int loc)
598 {
600  CommDataTypeTraits<T>::GetDataType(), pProc, request, loc);
601 }
602 
603 /**
604  * Creates a persistent request for a send
605  *
606  * @param pProc Rank of destination
607  * @param pData Array/vector to send
608  * @param count Number of elements to send in pData
609  * @param request Communication request object
610  * @param loc Location in request to use
611  */
612 template <class T>
613 void Comm::SendInit(int pProc, T &pData, int count,
614  const CommRequestSharedPtr &request, int loc)
615 {
617  CommDataTypeTraits<T>::GetDataType(), pProc, request, loc);
618 }
619 
620 /**
621  * Begins a nonblocking receive
622  *
623  * @param pProc Rank of source
624  * @param pData Array/vector to place incoming data in to
625  * @param count Number of elements to receive in to pData
626  * @param request Communication request object
627  * @param loc Location in request to use
628  */
629 template <class T>
630 void Comm::Irecv(int pProc, T &pData, int count,
631  const CommRequestSharedPtr &request, int loc)
632 {
634  CommDataTypeTraits<T>::GetDataType(), pProc, request, loc);
635 }
636 
637 /**
638  * Create a persistent request for a receive
639  *
640  * @param pProc Rank of source
641  * @param pData Array/vector to place incoming data in to
642  * @param count Number of elements to receive in to pData
643  * @param request Communication request object
644  * @param loc Location in request to use
645  */
646 template <class T>
647 void Comm::RecvInit(int pProc, T &pData, int count,
648  const CommRequestSharedPtr &request, int loc)
649 {
651  CommDataTypeTraits<T>::GetDataType(), pProc, request, loc);
652 }
653 
654 /**
655  * Starts a collection of persistent requests
656  *
657  * @param request Communication request object
658  */
659 inline void Comm::StartAll(const CommRequestSharedPtr &request)
660 {
661  v_StartAll(request);
662 }
663 
664 /**
665  * Waits for all CommRequests in the request object to complete.
666  *
667  * @param request Communication request object
668  */
669 inline void Comm::WaitAll(const CommRequestSharedPtr &request)
670 {
671  v_WaitAll(request);
672 }
673 
674 /**
675  * Creates a number of CommRequests.
676  *
677  * @param num Number of requests to generate in the communication request object
678  *
679  * @return Communication request object
680  */
682 {
683  return v_CreateRequest(num);
684 }
685 
686 /**
687  * @brief If the flag is non-zero create a new communicator.
688  */
690 {
691  return v_CommCreateIf(flag);
692 }
693 
694 /**
695  * @brief Splits this communicator into a grid of size pRows*pColumns
696  * and creates row and column communicators. By default the communicator
697  * is a single row.
698  */
699 inline void Comm::SplitComm(int pRows, int pColumns)
700 {
701  v_SplitComm(pRows, pColumns);
702 }
703 
704 /**
705  * @brief Retrieve the row communicator to which this process belongs.
706  */
708 {
709  if (!m_commRow.get())
710  {
711  return shared_from_this();
712  }
713  else
714  {
715  return m_commRow;
716  }
717 }
718 
719 /**
720  * @brief Retrieve the column communicator to which this process
721  * belongs.
722  */
724 {
725  if (!m_commColumn.get())
726  {
727  return shared_from_this();
728  }
729  else
730  {
731  return m_commColumn;
732  }
733 }
734 
736 {
737  return v_TreatAsRankZero();
738 }
739 
740 inline bool Comm::IsSerial()
741 {
742  return v_IsSerial();
743 }
744 
745 /**
746  * @return tuple of {major, minor, patch} version numbers
747  */
748 inline std::tuple<int, int, int> Comm::GetVersion()
749 {
750  return v_GetVersion();
751 }
752 
754 {
755  return v_RemoveExistingFiles();
756 }
757 
758 std::pair<CommSharedPtr, CommSharedPtr> Comm::SplitCommNode()
759 {
760  return v_SplitCommNode();
761 }
762 
763 } // namespace LibUtilities
764 } // namespace Nektar
765 
766 #endif
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define LIB_UTILITIES_EXPORT
Base communications class.
Definition: Comm.h:90
void SendRecv(int pSendProc, T &pSendData, int pRecvProc, T &pRecvData)
Definition: Comm.h:324
void AllGather(T &pSendData, T &pRecvData)
Definition: Comm.h:398
virtual CommSharedPtr v_CommCreateIf(int flag)=0
void AlltoAll(T &pSendData, T &pRecvData)
Definition: Comm.h:356
virtual std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode()
CommSharedPtr m_commColumn
Column communicator.
Definition: Comm.h:178
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:689
CommSharedPtr GetColumnComm()
Retrieve the column communicator to which this process belongs.
Definition: Comm.h:723
bool RemoveExistingFiles()
Definition: Comm.h:753
T Gather(int rootProc, T &val)
Definition: Comm.h:478
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:293
CommSharedPtr GetRowComm()
Retrieve the row communicator to which this process belongs.
Definition: Comm.h:707
CommRequestSharedPtr CreateRequest(int num)
Definition: Comm.h:681
NekDouble Wtime()
Return the time in seconds.
Definition: Comm.h:301
void StartAll(const CommRequestSharedPtr &request)
Definition: Comm.h:659
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:463
CommSharedPtr m_commRow
Row communicator.
Definition: Comm.h:177
const std::string & GetType() const
Definition: Comm.h:285
void SendRecvReplace(int pSendProc, int pRecvProc, T &pData)
Definition: Comm.h:338
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:455
int GetSize() const
Returns number of processes.
Definition: Comm.h:269
void SendInit(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
Definition: Comm.h:613
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
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
void AllGatherv(T &pSendData, T &pRecvData, Array< OneD, int > &pRecvDataSizeMap, Array< OneD, int > &pRecvDataOffsetMap)
Definition: Comm.h:419
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc)=0
void Send(int pProc, T &pData)
Definition: Comm.h:306
int m_size
Number of processes.
Definition: Comm.h:175
std::string m_type
Type of communication.
Definition: Comm.h:176
void Recv(int pProc, T &pData)
Definition: Comm.h:313
void WaitAll(const CommRequestSharedPtr &request)
Definition: Comm.h:669
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:349
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:758
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:647
virtual void v_Block()=0
std::tuple< int, int, int > GetVersion()
Definition: Comm.h:748
void Irecv(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
Definition: Comm.h:630
virtual void v_Finalise()=0
void AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap, T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
Definition: Comm.h:379
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 SplitComm(int pRows, int pColumns)
Splits this communicator into a grid of size pRows*pColumns and creates row and column communicators....
Definition: Comm.h:699
void DistGraphCreateAdjacent(T &sources, T &sourceweights, int reorder)
Definition: Comm.h:528
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:596
T Scatter(int rootProc, T &pData)
Definition: Comm.h:497
virtual bool v_TreatAsRankZero()=0
virtual void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc)=0
virtual void v_SplitComm(int pRows, int pColumns)=0
virtual bool v_IsSerial()=0
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:564
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:61
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:1
double NekDouble