HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_SplittableRange.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GA_SplittableRange.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_SplittableRange__
12 #define __GA_SplittableRange__
13 
14 #include "GA_API.h"
15 #include "GA_Range.h"
16 #include "GA_Types.h"
17 
18 #include <UT/UT_ParallelUtil.h> // for UT_Split
19 
20 #include <stddef.h>
21 
22 
23 class GA_PageIterator;
25 
26 class UT_JobInfo;
27 
28 
29 /// A range which can be split into multiple ranges for threading
30 ///
31 /// A GA_SplittableRange can be split into separate ranges. All split ranges
32 /// are guaranteed to not cross page boundaries, so each split range can be
33 /// worked on by independent threads.
34 ///
35 /// The range conforms to tbb::range semantics, but also provides methods for
36 /// UT_ThreadedAlgorithm.
38 {
39 public:
40  /// Default constructor; object must be assigned before use.
42  /// Construct a splittable range from any arbitrary range
44  /// Copy c-tor
46  /// Move c-tor
49 
52 
53  /// @{
54  /// UT_ParallelUtil interface
56  : GA_Range()
57  {
58  range.split(range, *this);
59  }
60  bool is_divisible() const
61  {
62  return myRange->is_divisible();
63  }
64  /// @}
65 
66  /// Convenience method to test whether we can multi-thread
67  bool canMultiThread() const { return is_divisible(); }
68 
69  /// Return the number of pages
71  { return myRange->getPageCount(); }
72  /// Get the offset of the first element in a page
73  GA_Offset getFirstOffsetInPage(GA_Size relative_page) const
74  { return myRange->getFirstOffsetInPage(relative_page); }
75  /// Get an iterator over the elements in a given page
76  GA_Range getPageElementRange(GA_Size relative_page) const;
77 
78  /// @{
79  /// Create an iterator over the pages in the range
80  GA_PageIterator beginPages() const;
81  GA_PageIterator beginPages(const UT_JobInfo &jobinfo) const;
82  /// @}
83 
84  /// Get a range of elements for a given job
85  GA_Range getJobElementRange(const UT_JobInfo &info) const;
86 
87  /// Static method to divide work for UT_ThreadedAlgorithm.
88  static inline GA_Range divideWork(const GA_Range &r, const UT_JobInfo &j)
89  {
90  return GA_SplittableRange(r).getJobElementRange(j);
91  }
92 
93  /// Split this range into two new ranges by splitting the RTI
95  GA_SplittableRange &d2) const
96  {
97  GA_RangeTypeInterface *list[2];
98  if (!myRange->is_divisible() || !myRange->split(list))
99  return false;
100  d1.setRange(list[0]);
101  d2.setRange(list[1]);
102  return true;
103  }
104 private:
105 };
106 
107 /// This is needed by the tbb wrapper in UT_ParallelUtility
108 /// It returns an upper bound for the actual number of work items
109 /// in the range.
111 {
112  return range.getMaxEntries();
113 }
114 
115 #endif
116 
GA_API size_t UTestimatedNumItems(const GA_SplittableRange &range)
GLenum GLint * range
Definition: glcorearb.h:1925
tbb::split UT_Split
Definition: GA_PolyCounts.h:24
GA_Size getPageCount() const
Return the number of pages.
friend class GA_SplittableRange
Definition: GA_Range.h:313
#define GA_API
Definition: GA_API.h:14
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:641
bool split(GA_SplittableRange &d1, GA_SplittableRange &d2) const
Split this range into two new ranges by splitting the RTI.
GA_Size getMaxEntries() const
Get an upper bound on the range.
Definition: GA_Range.h:250
bool is_divisible() const
Abstract implementation of a range.
GLint j
Definition: glad.h:2733
const GA_Range & operator=(const GA_Range &src)
Definition: GA_Range.h:220
GA_SplittableRange()
Default constructor; object must be assigned before use.
GA_Offset getFirstOffsetInPage(GA_Size relative_page) const
Get the offset of the first element in a page.
GLboolean r
Definition: glcorearb.h:1222
bool canMultiThread() const
Convenience method to test whether we can multi-thread.
static GA_Range divideWork(const GA_Range &r, const UT_JobInfo &j)
Static method to divide work for UT_ThreadedAlgorithm.