Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
Loading...
Searching...
No Matches
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...
 
virtual taskexecute ()=0
 Should be overridden by derived classes. More...
 
internal::allocate_continuation_proxyallocate_continuation ()
 Returns proxy for overloaded new that allocates a continuation task of *this. More...
 
internal::allocate_child_proxyallocate_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...
 
bool is_enqueued_task () const
 True if the task was enqueued. 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...
 
__TBB_DEPRECATED void set_group_priority (priority_t p)
 Changes priority of the task group this task belongs to. More...
 
__TBB_DEPRECATED 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 186 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 188 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 187 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 201 of file parallel_scan.h.

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

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 214 of file parallel_scan.h.

214 :
215 my_body(&body_),
216 my_sum(NULL),
217 my_return_slot(&return_slot_),
218 my_parent_sum(NULL),
219 my_is_final(true),
220 my_is_right_child(false),
221 my_range(range_),
222 my_partition(partitioner_)
223 {
224 __TBB_ASSERT( !*my_return_slot, NULL );
225 }

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 254 of file parallel_scan.h.

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

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 227 of file parallel_scan.h.

227 {
228 if( !range_.empty() ) {
229 typedef internal::start_scan<Range,Body,Partitioner> start_pass1_type;
230 internal::sum_node<Range,Body>* root = NULL;
231 final_sum_type* temp_body = new(task::allocate_root()) final_sum_type( body_ );
232 start_pass1_type& pass1 = *new(task::allocate_root()) start_pass1_type(
233 /*my_return_slot=*/root,
234 range_,
235 *temp_body,
236 partitioner_ );
237 temp_body->my_body.reverse_join(body_);
239 if( root ) {
240 root->my_body = temp_body;
241 root->my_incoming = NULL;
242 root->my_stuff_last = &body_;
244 } else {
245 body_.assign(temp_body->my_body);
246 temp_body->finish_construction( range_, NULL );
247 temp_body->destroy(*temp_body);
248 }
249 }
250 }
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:808

References tbb::task::allocate_root(), tbb::internal::final_sum< Range, Body >::finish_construction(), tbb::internal::final_sum< Range, Body >::my_body, tbb::internal::sum_node< Range, Body >::my_body, tbb::internal::sum_node< Range, Body >::my_incoming, tbb::internal::sum_node< 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 189 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 195 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 194 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 198 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 197 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 191 of file parallel_scan.h.


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

Copyright © 2005-2020 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.