HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ParallelPipeline.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  * COMMENTS: Wrapper around tbb::parallel_pipeline
7  */
8 
9 #ifndef __UT_ParallelPipeline__
10 #define __UT_ParallelPipeline__
11 
12 #include <tbb/pipeline.h>
13 
14 namespace UT_ParallelPipeline
15 {
16  /// @brief A filter (task) that will make up part of the pipeline.
17  /// @tparam Receives The type that this filter receives for an upstream
18  /// filter. void if it is the first filter in a pipeline.
19  /// @tparam Provides The type that this filter provides to a downstream
20  /// filter. void if it is the last filter in a pipeline.
21  template<typename Receives, typename Provides>
22  using Filter = tbb::filter_t<Receives, Provides>;
23 
24  /// @brief The execution mode of a filter.
25  enum Mode
26  {
27  Parallel = tbb::filter::mode::parallel,
28  SerialInOrder = tbb::filter::mode::serial_in_order,
29  SerialOutOfOrder = tbb::filter::mode::serial_out_of_order,
30  Serial = tbb::filter::mode::serial
31  };
32 
33  /// @brief The control to signal end-of-input for the pipeline.
34  using FlowControl = tbb::flow_control;
35 };
36 
37 /// @brief Create a filter (task) that will make up part of the pipeline.
38 /// @param mode The execution mode of this filter.
39 /// @param body The function or lambda that should be executed.
40 template<typename Receives, typename Provides, typename Body>
42  UT_ParallelPipeline::Mode mode, const Body& body)
43 {
44  return tbb::make_filter<Receives, Provides>(
45  static_cast<tbb::filter::mode>(mode), body);
46 }
47 
48 /// @brief Run the pipeline
49 ///
50 /// The pipeline is defined by providing a number of filters to \p filter_chain
51 /// The pipeline will run with at most \p max_number_of_live_tokens items
52 /// simultaneously.
53 ///
54 /// @param max_number_of_live_tokens The maximum number of items to run simultaneously.
55 /// @param filter_chain The filters that make up the pipeline.
56 inline void UTrunParallelPipeline(size_t max_number_of_live_tokens,
57  const UT_ParallelPipeline::Filter<void,void>& filter_chain)
58 {
59  return tbb::parallel_pipeline(max_number_of_live_tokens, filter_chain);
60 }
61 
62 #endif // __UT_ParallelPipeline__
void UTrunParallelPipeline(size_t max_number_of_live_tokens, const UT_ParallelPipeline::Filter< void, void > &filter_chain)
Run the pipeline.
tbb::filter_t< Receives, Provides > Filter
A filter (task) that will make up part of the pipeline.
Mode
The execution mode of a filter.
tbb::flow_control FlowControl
The control to signal end-of-input for the pipeline.
GLenum mode
Definition: glcorearb.h:99
UT_ParallelPipeline::Filter< Receives, Provides > UTmakeParallelPipelineFilter(UT_ParallelPipeline::Mode mode, const Body &body)
Create a filter (task) that will make up part of the pipeline.