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  /// Construct a splittable range from any arbitrary range
42  /// Copy c-tor
45  {
46  }
47 
48  /// @{
49  /// UT_ParallelUtil interface
51  : GA_Range()
52  {
53  range.split(range, *this);
54  }
55  bool is_divisible() const
56  {
57  return myRange->is_divisible();
58  }
59  /// @}
60 
61  /// Convenience method to test whether we can multi-thread
62  bool canMultiThread() const { return is_divisible(); }
63 
64  /// Return the number of pages
66  { return myRange->getPageCount(); }
67  /// Get the offset of the first element in a page
68  GA_Offset getFirstOffsetInPage(GA_Size relative_page) const
69  { return myRange->getFirstOffsetInPage(relative_page); }
70  /// Get an iterator over the elements in a given page
71  GA_Range getPageElementRange(GA_Size relative_page) const;
72 
73  /// @{
74  /// Create an iterator over the pages in the range
75  GA_PageIterator beginPages() const;
76  GA_PageIterator beginPages(const UT_JobInfo &jobinfo) const;
77  /// @}
78 
79  /// Get a range of elements for a given job
80  GA_Range getJobElementRange(const UT_JobInfo &info) const;
81 
82  /// Static method to divide work for UT_ThreadedAlgorithm.
83  static inline GA_Range divideWork(const GA_Range &r, const UT_JobInfo &j)
84  {
85  return GA_SplittableRange(r).getJobElementRange(j);
86  }
87 
88  /// Split this range into two new ranges by splitting the RTI
90  GA_SplittableRange &d2) const
91  {
92  GA_RangeTypeInterface *list[2];
93  if (!myRange->is_divisible() || !myRange->split(list))
94  return false;
95  d1.setRange(list[0]);
96  d2.setRange(list[1]);
97  return true;
98  }
99 private:
100 };
101 
102 /// This is needed by the tbb wrapper in UT_ParallelUtility
103 /// It returns an upper bound for the actual number of work items
104 /// in the range.
106 {
107  return range.getMaxEntries();
108 }
109 
110 #endif
111 
GA_API size_t UTestimatedNumItems(const GA_SplittableRange &range)
GLenum GLint * range
Definition: glcorearb.h:1924
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:303
#define GA_API
Definition: GA_API.h:12
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
GA_SplittableRange(GA_SplittableRange &range, UT_Split)
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:240
bool is_divisible() const
Abstract implementation of a range.
GA_Offset getFirstOffsetInPage(GA_Size relative_page) const
Get the offset of the first element in a page.
GLboolean r
Definition: glcorearb.h:1221
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.