IFEM  90A354
ThreadGroups.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
12 //==============================================================================
13 
14 #ifndef _THREAD_GROUPS_H
15 #define _THREAD_GROUPS_H
16 
17 #include <vector>
18 #include <cstddef>
19 
20 
26 {
27  typedef std::vector<bool> BoolVec;
28  typedef std::vector<int> IntVec;
29  typedef std::vector<IntVec> IntMat;
30 
31 public:
33  enum StripDirection { NONE, U, V, W, ANY };
34 
36  explicit ThreadGroups(StripDirection dir = ANY) : stripDir(dir) {}
37 
43  void calcGroups(const BoolVec& el1, const BoolVec& el2,
44  int p1, int p2);
49  void calcGroups(int nel1, int nel2, int minsize);
50 
58  void calcGroups(const BoolVec& el1, const BoolVec& el2, const BoolVec& el3,
59  int p1, int p2, int p3);
65  void calcGroups(int nel1, int nel2, int nel3, int minsize);
68  void oneGroup(size_t nel);
72  void oneGroup(size_t nel, const IntVec& elms);
75  void oneStripe(size_t nel);
79  void oneStripe(size_t nel, const IntVec& elms);
80 
83  void applyMap(const IntVec& map);
84 
86  size_t size() const { return tg[1].empty() ? 1 : 2; }
88  bool empty() const { return tg[0].empty() && tg[1].empty(); }
90  const IntMat& operator[](int i) const { return tg[i]; }
92  IntMat& operator[](int i) { return tg[i]; }
93 
95  ThreadGroups filter(const IntVec& elmList) const;
96 
98  void analyzeUnstruct(bool listAllSizes = false) const;
99 
100 protected:
102  static StripDirection getStripDirection(int nel1, int nel2,
103  int parts);
105  static StripDirection getStripDirection(int nel1, int nel2, int nel3,
106  int parts);
107 
108 public:
110 
111 private:
112  IntMat tg[2];
113 };
114 
115 #endif
std::vector< int > IntVec
General integer vector.
Definition: ASMbase.h:25
Class containing threading group partitioning.
Definition: ThreadGroups.h:26
bool empty() const
Return true if both groups are empty.
Definition: ThreadGroups.h:88
void calcGroups(const BoolVec &el1, const BoolVec &el2, int p1, int p2)
Calculates a 2D thread group partitioning based on stripes.
Definition: ThreadGroups.C:88
IntMat & operator[](int i)
Indexing operator.
Definition: ThreadGroups.h:92
StripDirection stripDir
Actual direction to split elements.
Definition: ThreadGroups.h:109
const IntMat & operator[](int i) const
Indexing operator.
Definition: ThreadGroups.h:90
void applyMap(const IntVec &map)
Maps a partitioning through a map.
Definition: ThreadGroups.C:481
StripDirection
Directions to consider for element stripes.
Definition: ThreadGroups.h:33
std::vector< bool > BoolVec
List of boolean flags.
Definition: ThreadGroups.h:27
void oneGroup(size_t nel)
Initializes the threading groups in case of no multi-threading.
Definition: ThreadGroups.C:45
void analyzeUnstruct(bool listAllSizes=false) const
Analyze and print thread group statistics for unstructured ASMs.
Definition: ThreadGroups.C:507
void oneStripe(size_t nel)
Initializes the threading groups in case of a single stripe.
Definition: ThreadGroups.C:65
size_t size() const
Returns the number of groups.
Definition: ThreadGroups.h:86
IntMat tg[2]
Threading groups (always two, but the second may be empty)
Definition: ThreadGroups.h:112
ThreadGroups filter(const IntVec &elmList) const
Filters current threading groups through a white-list of elements.
Definition: ThreadGroups.C:490
std::vector< int > IntVec
List of elements on one thread.
Definition: ThreadGroups.h:28
ThreadGroups(StripDirection dir=ANY)
Default constructor.
Definition: ThreadGroups.h:36
static StripDirection getStripDirection(int nel1, int nel2, int parts)
Calculates the parameter direction of the treading stripes in 2D.
Definition: ThreadGroups.C:426
std::vector< IntVec > IntMat
Element lists for all threads.
Definition: ThreadGroups.h:29