tbb::internal::start_scan< Range, Body, Partitioner > Class Template Reference
Algorithms

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...
task * | parent () 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_context * | context ()
| This method is deprecated and will be removed in the future. More...
task_group_context * | group ()
| 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 __TBB_DEPRECATED void | enqueue (task &t, priority_t p)
| Enqueue task for starvation-resistant execution on the specified priority level. More...
static __TBB_DEPRECATED 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

task * | execute () __TBB_override
| Should be overridden by derived classes. More...

## Private Attributes

final_sum_type * | my_body
final_sum_type ** | my_sum
sum_node_type ** | my_return_slot
sum_node_type * | my_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.

:
my_body(parent_.my_body),
my_sum(parent_.my_sum),
my_return_slot(&return_slot_),
my_parent_sum(parent_sum_),
my_is_final(parent_.my_is_final),
my_is_right_child(false),
my_range(parent_.my_range,split()),
my_partition(parent_.my_partition,split())
{
__TBB_ASSERT( !*my_return_slot, NULL );
}

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.

:
my_body(&body_),
my_sum(NULL),
my_return_slot(&return_slot_),
my_parent_sum(NULL),
my_is_final(true),
my_is_right_child(false),
my_range(range_),
my_partition(partitioner_)
{
__TBB_ASSERT( !*my_return_slot, NULL );
}

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 | ( |  | ) |

private virtual

Should be overridden by derived classes.

Implements tbb::task.

Definition at line 254 of file parallel_scan.h.

{
typedef internal::finish_scan<Range,Body> finish_pass1_type;
finish_pass1_type* p = my_parent_sum ? static_cast<finish_pass1_type*>( parent() ) : NULL;
// Inspecting p->result.left_sum would ordinarily be a race condition.
// But we inspect it only if we are not a stolen task, in which case we
// know that task assigning to p->result.left_sum has completed.
bool treat_as_stolen = my_is_right_child && (is_stolen_task() || my_body!=p->my_result.my_left_sum);
if( treat_as_stolen ) {
// Invocation is for right child that has been really stolen or needs to be virtually stolen
p->my_right_zombie = my_body = new( allocate_root() ) final_sum_type(my_body->my_body);
my_is_final = false;
}
task* next_task = NULL;
if( (my_is_right_child && !treat_as_stolen) || !my_range.is_divisible() || my_partition.should_execute_range(*this) ) {
if( my_is_final )
(my_body->my_body)( my_range, final_scan_tag() );
else if( my_sum )
(my_body->my_body)( my_range, pre_scan_tag() );
if( my_sum )
*my_sum = my_body;
__TBB_ASSERT( !*my_return_slot, NULL );
} else {
sum_node_type* result;
if( my_parent_sum )
result = new(allocate_additional_child_of(*my_parent_sum)) sum_node_type(my_range,/*my_left_is_final=*/my_is_final);
else
result = new(task::allocate_root()) sum_node_type(my_range,/*my_left_is_final=*/my_is_final);
finish_pass1_type& c = *new( allocate_continuation()) finish_pass1_type(*my_return_slot,my_sum,*result);
// Split off right child
start_scan& b = *new( c.allocate_child() ) start_scan( /*my_return_slot=*/result->my_right, *this, result );
b.my_is_right_child = true;
// Left child is recycling of *this. Must recycle this before spawning b,
// otherwise b might complete and decrement c.ref_count() to zero, which
// would cause c.execute() to run prematurely.
recycle_as_child_of(c);
c.set_ref_count(2);
c.spawn(b);
my_sum = &result->my_left_sum;
my_return_slot = &result->my_left;
my_is_right_child = false;
next_task = this;
my_parent_sum = result;
__TBB_ASSERT( !*my_return_slot, NULL );
}
return next_task;
}

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_
| ) |  |

inline static

Definition at line 227 of file parallel_scan.h.

{
if( !range_.empty() ) {
typedef internal::start_scan<Range,Body,Partitioner> start_pass1_type;
internal::sum_node<Range,Body>* root = NULL;
final_sum_type* temp_body = new(task::allocate_root()) final_sum_type( body_ );
start_pass1_type& pass1 = *new(task::allocate_root()) start_pass1_type(
/*my_return_slot=*/root,
range_,
*temp_body,
partitioner_ );
temp_body->my_body.reverse_join(body_);
task::spawn_root_and_wait( pass1 );
if( root ) {
root->my_body = temp_body;
root->my_incoming = NULL;
root->my_stuff_last = &body_;
task::spawn_root_and_wait( *root );
} else {
body_.assign(temp_body->my_body);
temp_body->finish_construction( range_, NULL );
temp_body->destroy(*temp_body);
}
}
}

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

Definition at line 196 of file parallel_scan.h.

Referenced by tbb::internal::start_scan< Range, Body, Partitioner >::execute().

## 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

Definition at line 192 of file parallel_scan.h.

Referenced by tbb::internal::start_scan< Range, Body, Partitioner >::start_scan().

## 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:

- parallel_scan.h

__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::internal::start_scan::my_parent_sum
sum_node_type * my_parent_sum
Definition: parallel_scan.h:194
tbb::internal::start_scan::my_return_slot
sum_node_type ** my_return_slot
Definition: parallel_scan.h:192
tbb::internal::start_scan::my_body
final_sum_type * my_body
Definition: parallel_scan.h:189
tbb::internal::start_scan::my_is_right_child
bool my_is_right_child
Definition: parallel_scan.h:196
tbb::task::task
task()
Default constructor.
Definition: task.h:614
tbb::internal::sum_node::my_left
sum_node * my_left
Definition: parallel_scan.h:90
tbb::internal::start_scan::my_partition
Partitioner::partition_type my_partition
Definition: parallel_scan.h:198
tbb::task::is_stolen_task
bool is_stolen_task() const
True if task was stolen from the task pool of another thread.
Definition: task.h:874
tbb::internal::start_scan::final_sum_type
final_sum< Range, Body > final_sum_type
Definition: parallel_scan.h:188
tbb::task::recycle_as_child_of
void recycle_as_child_of(task &new_parent)
Change this to be a child of new_parent.
Definition: task.h:714
tbb::internal::start_scan::sum_node_type
sum_node< Range, Body > sum_node_type
Definition: parallel_scan.h:187
tbb::task::parent
task * parent() const
task on whose behalf this task is working, or NULL if this is a root.
Definition: task.h:854
tbb::internal::start_scan::my_is_final
bool my_is_final
Definition: parallel_scan.h:195
tbb::task::allocate_root
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:652
tbb::internal::start_scan::my_range
Range my_range
Definition: parallel_scan.h:197
tbb::internal::start_scan::start_scan
start_scan(sum_node_type *&return_slot_, start_scan &parent_, sum_node_type *parent_sum_)
Definition: parallel_scan.h:201
tbb::internal::final_sum::my_body
Body my_body
Definition: parallel_scan.h:52
tbb::internal::start_scan::my_sum
final_sum_type ** my_sum
Definition: parallel_scan.h:191
tbb::task::allocate_continuation
internal::allocate_continuation_proxy & allocate_continuation()
Returns proxy for overloaded new that allocates a continuation task of *this.
Definition: task.h:665
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
tbb::task::spawn_root_and_wait
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:797

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.