Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::internal::start_scan< Range, Body, Partitioner > Class Template Reference

Initial task to split the work. More...

#include <parallel_scan.h>

Inheritance diagram for tbb::internal::start_scan< Range, Body, Partitioner >:
Collaboration diagram for tbb::internal::start_scan< Range, Body, Partitioner >:

Public Member Functions

 start_scan (sum_node_type *&return_slot_, start_scan &parent_, sum_node_type *parent_sum_)
 
 start_scan (sum_node_type *&return_slot_, const Range &range_, final_sum_type &body_, const Partitioner &partitioner_)
 
- Public Member Functions inherited from tbb::task
virtual ~task ()
 Destructor. More...
 
internal::allocate_continuation_proxy & allocate_continuation ()
 Returns proxy for overloaded new that allocates a continuation task of *this. More...
 
internal::allocate_child_proxy & allocate_child ()
 Returns proxy for overloaded new that allocates a child task of *this. More...
 
void recycle_as_continuation ()
 Change this to be a continuation of its former self. More...
 
void recycle_as_safe_continuation ()
 Recommended to use, safe variant of recycle_as_continuation. More...
 
void recycle_as_child_of (task &new_parent)
 Change this to be a child of new_parent. More...
 
void recycle_to_reexecute ()
 Schedule this for reexecution after current execute() returns. More...
 
void set_ref_count (int count)
 Set reference count. More...
 
void increment_ref_count ()
 Atomically increment reference count. More...
 
int add_ref_count (int count)
 Atomically adds to reference count and returns its new value. More...
 
int decrement_ref_count ()
 Atomically decrement reference count and returns its new value. More...
 
void spawn_and_wait_for_all (task &child)
 Similar to spawn followed by wait_for_all, but more efficient. More...
 
void __TBB_EXPORTED_METHOD spawn_and_wait_for_all (task_list &list)
 Similar to spawn followed by wait_for_all, but more efficient. More...
 
void wait_for_all ()
 Wait for reference count to become one, and set reference count to zero. More...
 
taskparent () const
 task on whose behalf this task is working, or NULL if this is a root. More...
 
void set_parent (task *p)
 sets parent task pointer to specified value More...
 
task_group_contextcontext ()
 This method is deprecated and will be removed in the future. More...
 
task_group_contextgroup ()
 Pointer to the task group descriptor. More...
 
bool is_stolen_task () const
 True if task was stolen from the task pool of another thread. More...
 
state_type state () const
 Current execution state. More...
 
int ref_count () const
 The internal reference count. More...
 
bool __TBB_EXPORTED_METHOD is_owned_by_current_thread () const
 Obsolete, and only retained for the sake of backward compatibility. Always returns true. More...
 
void set_affinity (affinity_id id)
 Set affinity for this task. More...
 
affinity_id affinity () const
 Current affinity of this task. More...
 
virtual void __TBB_EXPORTED_METHOD note_affinity (affinity_id id)
 Invoked by scheduler to notify task that it ran on unexpected thread. More...
 
void __TBB_EXPORTED_METHOD change_group (task_group_context &ctx)
 Moves this task from its current group into another one. More...
 
bool cancel_group_execution ()
 Initiates cancellation of all tasks in this cancellation group and its subordinate groups. More...
 
bool is_cancelled () const
 Returns true if the context has received cancellation request. More...
 
void set_group_priority (priority_t p)
 Changes priority of the task group this task belongs to. More...
 
priority_t group_priority () const
 Retrieves current priority of the task group this task belongs to. More...
 

Static Public Member Functions

static void run (const Range &range_, Body &body_, const Partitioner &partitioner_)
 
- Static Public Member Functions inherited from tbb::task
static internal::allocate_root_proxy allocate_root ()
 Returns proxy for overloaded new that allocates a root task. More...
 
static internal::allocate_root_with_context_proxy allocate_root (task_group_context &ctx)
 Returns proxy for overloaded new that allocates a root task associated with user supplied context. More...
 
static void spawn_root_and_wait (task &root)
 Spawn task allocated by allocate_root, wait for it to complete, and deallocate it. More...
 
static void spawn_root_and_wait (task_list &root_list)
 Spawn root tasks on list and wait for all of them to finish. More...
 
static void enqueue (task &t)
 Enqueue task for starvation-resistant execution. More...
 
static void enqueue (task &t, priority_t p)
 Enqueue task for starvation-resistant execution on the specified priority level. More...
 
static void enqueue (task &t, task_arena &arena, priority_t p=priority_t(0))
 Enqueue task in task_arena. More...
 
static task &__TBB_EXPORTED_FUNC self ()
 The innermost task being executed or destroyed by the current thread at the moment. More...
 

Private Types

typedef sum_node< Range, Body > sum_node_type
 
typedef final_sum< Range, Body > final_sum_type
 

Private Member Functions

taskexecute () __TBB_override
 Should be overridden by derived classes. More...
 

Private Attributes

final_sum_typemy_body
 
final_sum_type ** my_sum
 
sum_node_type ** my_return_slot
 
sum_node_typemy_parent_sum
 
bool my_is_final
 
bool my_is_right_child
 
Range my_range
 
Partitioner::partition_type my_partition
 

Additional Inherited Members

- Public Types inherited from tbb::task
enum  state_type {
  executing, reexecute, ready, allocated,
  freed, recycle
}
 Enumeration of task states that the scheduler considers. More...
 
typedef internal::affinity_id affinity_id
 An id as used for specifying affinity. More...
 
- Protected Member Functions inherited from tbb::task
 task ()
 Default constructor. More...
 

Detailed Description

template<typename Range, typename Body, typename Partitioner = simple_partitioner>
class tbb::internal::start_scan< Range, Body, Partitioner >

Initial task to split the work.

Definition at line 183 of file parallel_scan.h.

Member Typedef Documentation

◆ final_sum_type

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
typedef final_sum<Range,Body> tbb::internal::start_scan< Range, Body, Partitioner >::final_sum_type
private

Definition at line 185 of file parallel_scan.h.

◆ sum_node_type

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
typedef sum_node<Range,Body> tbb::internal::start_scan< Range, Body, Partitioner >::sum_node_type
private

Definition at line 184 of file parallel_scan.h.

Constructor & Destructor Documentation

◆ start_scan() [1/2]

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
tbb::internal::start_scan< Range, Body, Partitioner >::start_scan ( sum_node_type *&  return_slot_,
start_scan< Range, Body, Partitioner > &  parent_,
sum_node_type parent_sum_ 
)
inline

Definition at line 198 of file parallel_scan.h.

198  :
199  my_body(parent_.my_body),
200  my_sum(parent_.my_sum),
201  my_return_slot(&return_slot_),
202  my_parent_sum(parent_sum_),
203  my_is_final(parent_.my_is_final),
204  my_is_right_child(false),
205  my_range(parent_.my_range,split()),
206  my_partition(parent_.my_partition,split())
207  {
208  __TBB_ASSERT( !*my_return_slot, NULL );
209  }
final_sum_type * my_body
Partitioner::partition_type my_partition
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
sum_node_type ** my_return_slot
sum_node_type * my_parent_sum
final_sum_type ** my_sum

References __TBB_ASSERT, and tbb::internal::start_scan< Range, Body, Partitioner >::my_return_slot.

◆ start_scan() [2/2]

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
tbb::internal::start_scan< Range, Body, Partitioner >::start_scan ( sum_node_type *&  return_slot_,
const Range &  range_,
final_sum_type body_,
const Partitioner &  partitioner_ 
)
inline

Definition at line 211 of file parallel_scan.h.

211  :
212  my_body(&body_),
213  my_sum(NULL),
214  my_return_slot(&return_slot_),
215  my_parent_sum(NULL),
216  my_is_final(true),
217  my_is_right_child(false),
218  my_range(range_),
219  my_partition(partitioner_)
220  {
221  __TBB_ASSERT( !*my_return_slot, NULL );
222  }
final_sum_type * my_body
Partitioner::partition_type my_partition
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
sum_node_type ** my_return_slot
sum_node_type * my_parent_sum
final_sum_type ** my_sum

References __TBB_ASSERT, and tbb::internal::start_scan< Range, Body, Partitioner >::my_return_slot.

Member Function Documentation

◆ execute()

template<typename Range , typename Body , typename Partitioner >
task * tbb::internal::start_scan< Range, Body, Partitioner >::execute ( )
privatevirtual

Should be overridden by derived classes.

Implements tbb::task.

Definition at line 251 of file parallel_scan.h.

251  {
252  typedef internal::finish_scan<Range,Body> finish_pass1_type;
253  finish_pass1_type* p = my_parent_sum ? static_cast<finish_pass1_type*>( parent() ) : NULL;
254  // Inspecting p->result.left_sum would ordinarily be a race condition.
255  // But we inspect it only if we are not a stolen task, in which case we
256  // know that task assigning to p->result.left_sum has completed.
257  bool treat_as_stolen = my_is_right_child && (is_stolen_task() || my_body!=p->my_result.my_left_sum);
258  if( treat_as_stolen ) {
259  // Invocation is for right child that has been really stolen or needs to be virtually stolen
260  p->my_right_zombie = my_body = new( allocate_root() ) final_sum_type(my_body->my_body);
261  my_is_final = false;
262  }
263  task* next_task = NULL;
264  if( (my_is_right_child && !treat_as_stolen) || !my_range.is_divisible() || my_partition.should_execute_range(*this) ) {
265  if( my_is_final )
266  (my_body->my_body)( my_range, final_scan_tag() );
267  else if( my_sum )
268  (my_body->my_body)( my_range, pre_scan_tag() );
269  if( my_sum )
270  *my_sum = my_body;
271  __TBB_ASSERT( !*my_return_slot, NULL );
272  } else {
273  sum_node_type* result;
274  if( my_parent_sum )
275  result = new(allocate_additional_child_of(*my_parent_sum)) sum_node_type(my_range,/*my_left_is_final=*/my_is_final);
276  else
277  result = new(task::allocate_root()) sum_node_type(my_range,/*my_left_is_final=*/my_is_final);
278  finish_pass1_type& c = *new( allocate_continuation()) finish_pass1_type(*my_return_slot,my_sum,*result);
279  // Split off right child
280  start_scan& b = *new( c.allocate_child() ) start_scan( /*my_return_slot=*/result->my_right, *this, result );
281  b.my_is_right_child = true;
282  // Left child is recycling of *this. Must recycle this before spawning b,
283  // otherwise b might complete and decrement c.ref_count() to zero, which
284  // would cause c.execute() to run prematurely.
286  c.set_ref_count(2);
287  c.spawn(b);
288  my_sum = &result->my_left_sum;
289  my_return_slot = &result->my_left;
290  my_is_right_child = false;
291  next_task = this;
292  my_parent_sum = result;
293  __TBB_ASSERT( !*my_return_slot, NULL );
294  }
295  return next_task;
296  }
start_scan(sum_node_type *&return_slot_, start_scan &parent_, sum_node_type *parent_sum_)
bool is_stolen_task() const
True if task was stolen from the task pool of another thread.
Definition: task.h:855
final_sum_type * my_body
Partitioner::partition_type my_partition
task()
Default constructor.
Definition: task.h:599
void recycle_as_child_of(task &new_parent)
Change this to be a child of new_parent.
Definition: task.h:695
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
sum_node_type ** my_return_slot
internal::allocate_continuation_proxy & allocate_continuation()
Returns proxy for overloaded new that allocates a continuation task of *this.
Definition: task.h:646
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:633
task * parent() const
task on whose behalf this task is working, or NULL if this is a root.
Definition: task.h:835
final_sum< Range, Body > final_sum_type
sum_node_type * my_parent_sum
void const char const char int ITT_FORMAT __itt_group_sync p
final_sum_type ** my_sum
sum_node< Range, Body > sum_node_type

References __TBB_ASSERT, tbb::task::allocate_root(), tbb::internal::start_scan< Range, Body, Partitioner >::my_is_right_child, tbb::internal::sum_node< Range, Body >::my_left, tbb::internal::sum_node< Range, Body >::my_left_sum, tbb::internal::sum_node< Range, Body >::my_right, p, and parent.

Here is the call graph for this function:

◆ run()

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
static void tbb::internal::start_scan< Range, Body, Partitioner >::run ( const Range &  range_,
Body &  body_,
const Partitioner &  partitioner_ 
)
inlinestatic

Definition at line 224 of file parallel_scan.h.

224  {
225  if( !range_.empty() ) {
226  typedef internal::start_scan<Range,Body,Partitioner> start_pass1_type;
227  internal::sum_node<Range,Body>* root = NULL;
228  final_sum_type* temp_body = new(task::allocate_root()) final_sum_type( body_ );
229  start_pass1_type& pass1 = *new(task::allocate_root()) start_pass1_type(
230  /*my_return_slot=*/root,
231  range_,
232  *temp_body,
233  partitioner_ );
234  temp_body->my_body.reverse_join(body_);
235  task::spawn_root_and_wait( pass1 );
236  if( root ) {
237  root->my_body = temp_body;
238  root->my_incoming = NULL;
239  root->my_stuff_last = &body_;
240  task::spawn_root_and_wait( *root );
241  } else {
242  body_.assign(temp_body->my_body);
243  temp_body->finish_construction( range_, NULL );
244  temp_body->destroy(*temp_body);
245  }
246  }
247  }
static void spawn_root_and_wait(task &root)
Spawn task allocated by allocate_root, wait for it to complete, and deallocate it.
Definition: task.h:778
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:633
final_sum< Range, Body > final_sum_type

References tbb::task::allocate_root(), tbb::internal::final_sum< Range, Body >::finish_construction(), tbb::internal::final_sum< Range, Body >::my_body, tbb::internal::final_sum< Range, Body >::my_stuff_last, and tbb::task::spawn_root_and_wait().

Referenced by tbb::parallel_scan().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ my_body

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
final_sum_type* tbb::internal::start_scan< Range, Body, Partitioner >::my_body
private

Definition at line 186 of file parallel_scan.h.

◆ my_is_final

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
bool tbb::internal::start_scan< Range, Body, Partitioner >::my_is_final
private

Definition at line 192 of file parallel_scan.h.

◆ my_is_right_child

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
bool tbb::internal::start_scan< Range, Body, Partitioner >::my_is_right_child
private

◆ my_parent_sum

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
sum_node_type* tbb::internal::start_scan< Range, Body, Partitioner >::my_parent_sum
private

Null if computing root.

Definition at line 191 of file parallel_scan.h.

◆ my_partition

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
Partitioner::partition_type tbb::internal::start_scan< Range, Body, Partitioner >::my_partition
private

Definition at line 195 of file parallel_scan.h.

◆ my_range

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
Range tbb::internal::start_scan< Range, Body, Partitioner >::my_range
private

Definition at line 194 of file parallel_scan.h.

◆ my_return_slot

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
sum_node_type** tbb::internal::start_scan< Range, Body, Partitioner >::my_return_slot
private

◆ my_sum

template<typename Range , typename Body , typename Partitioner = simple_partitioner>
final_sum_type** tbb::internal::start_scan< Range, Body, Partitioner >::my_sum
private

Non-null if caller is requesting total.

Definition at line 188 of file parallel_scan.h.


The documentation for this class was generated from the following file:

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.