Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::flow::interface10::graph Class Reference

The graph class. More...

#include <_flow_graph_impl.h>

Inheritance diagram for tbb::flow::interface10::graph:
Collaboration diagram for tbb::flow::interface10::graph:

Classes

class  run_and_put_task
 
class  run_task
 
class  spawn_functor
 A functor that spawns a task. More...
 
class  wait_functor
 

Public Types

typedef graph_iterator< graph, graph_nodeiterator
 
typedef graph_iterator< const graph, const graph_nodeconst_iterator
 

Public Member Functions

 graph ()
 Constructs a graph with isolated task_group_context. More...
 
 graph (tbb::task_group_context &use_this_context)
 Constructs a graph with use_this_context as context. More...
 
 ~graph ()
 Destroys the graph. More...
 
void increment_wait_count ()
 
void decrement_wait_count ()
 
void reserve_wait () __TBB_override
 Used to register that an external entity may still interact with the graph. More...
 
void release_wait () __TBB_override
 Deregisters an external entity that may have interacted with the graph. More...
 
template<typename Receiver , typename Body >
void run (Receiver &r, Body body)
 Spawns a task that runs a body and puts its output to a specific receiver. More...
 
template<typename Body >
void run (Body body)
 Spawns a task that runs a function object. More...
 
void wait_for_all ()
 Wait until graph is idle and decrement_wait_count calls equals increment_wait_count calls. More...
 
tbb::taskroot_task ()
 Returns the root task of the graph. More...
 
iterator begin ()
 start iterator More...
 
iterator end ()
 end iterator More...
 
const_iterator begin () const
 start const iterator More...
 
const_iterator end () const
 end const iterator More...
 
const_iterator cbegin () const
 start const iterator More...
 
const_iterator cend () const
 end const iterator More...
 
bool is_cancelled ()
 return status of graph execution More...
 
bool exception_thrown ()
 
void reset (reset_flags f=rf_reset_protocol)
 
- Public Member Functions inherited from tbb::flow::interface10::graph_proxy
virtual ~graph_proxy ()
 

Private Types

typedef std::list< tbb::task * > task_list_type
 

Private Member Functions

void prepare_task_arena (bool reinit=false)
 
void register_node (graph_node *n)
 
void remove_node (graph_node *n)
 
- Private Member Functions inherited from tbb::internal::no_copy
 no_copy ()
 Allow default construction. More...
 

Private Attributes

tbb::taskmy_root_task
 
tbb::task_group_contextmy_context
 
bool own_context
 
bool cancelled
 
bool caught_exception
 
bool my_is_active
 
task_list_type my_reset_task_list
 
graph_nodemy_nodes
 
graph_nodemy_nodes_last
 
tbb::spin_mutex nodelist_mutex
 
tbb::task_arenamy_task_arena
 
internal::graph_task_priority_queue_t my_priority_queue
 

Friends

class graph_node
 
template<typename C , typename N >
class graph_iterator
 
template<typename Input , typename Output , typename Policy , typename Allocator >
class async_node
 
class tbb::interface7::internal::task_arena_base
 
void internal::activate_graph (graph &g)
 
void internal::deactivate_graph (graph &g)
 
bool internal::is_graph_active (graph &g)
 
void internal::spawn_in_graph_arena (graph &g, tbb::task &arena_task)
 
void internal::add_task_to_graph_reset_list (graph &g, tbb::task *tp)
 
template<typename F >
void internal::execute_in_graph_arena (graph &g, F &f)
 

Detailed Description

The graph class.

This class serves as a handle to the graph

Definition at line 200 of file _flow_graph_impl.h.

Member Typedef Documentation

◆ const_iterator

◆ iterator

◆ task_list_type

Definition at line 235 of file _flow_graph_impl.h.

Constructor & Destructor Documentation

◆ graph() [1/2]

tbb::flow::interface10::graph::graph ( )
inline

Constructs a graph with isolated task_group_context.

Definition at line 745 of file flow_graph.h.

745  : my_nodes(NULL), my_nodes_last(NULL), my_task_arena(NULL) {
747  own_context = true;
748  cancelled = false;
749  caught_exception = false;
750  my_context = new task_group_context(tbb::internal::FLOW_TASKS);
751  my_root_task = (new (task::allocate_root(*my_context)) empty_task);
754  my_is_active = true;
755 }
tbb::task_group_context * my_context
static void fgt_graph(void *)
void set_ref_count(int count)
Set reference count.
Definition: task.h:734
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:636
void prepare_task_arena(bool reinit=false)

◆ graph() [2/2]

tbb::flow::interface10::graph::graph ( tbb::task_group_context use_this_context)
inlineexplicit

Constructs a graph with use_this_context as context.

Definition at line 757 of file flow_graph.h.

757  :
758  my_context(&use_this_context), my_nodes(NULL), my_nodes_last(NULL), my_task_arena(NULL) {
760  own_context = false;
761  my_root_task = (new (task::allocate_root(*my_context)) empty_task);
764  my_is_active = true;
765 }
tbb::task_group_context * my_context
static void fgt_graph(void *)
void set_ref_count(int count)
Set reference count.
Definition: task.h:734
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:636
void prepare_task_arena(bool reinit=false)

◆ ~graph()

tbb::flow::interface10::graph::~graph ( )
inline

Destroys the graph.

Calls wait_for_all, then destroys the root task and context.

Definition at line 767 of file flow_graph.h.

767  {
768  wait_for_all();
770  tbb::task::destroy(*my_root_task);
771  if (own_context) delete my_context;
772  delete my_task_arena;
773 }
tbb::task_group_context * my_context
void set_ref_count(int count)
Set reference count.
Definition: task.h:734
void wait_for_all()
Wait until graph is idle and decrement_wait_count calls equals increment_wait_count calls.

References my_root_task, tbb::task::set_ref_count(), and wait_for_all().

Here is the call graph for this function:

Member Function Documentation

◆ begin() [1/2]

graph::iterator tbb::flow::interface10::graph::begin ( )
inline

start iterator

Definition at line 835 of file flow_graph.h.

835 { return iterator(this, true); }
graph_iterator< graph, graph_node > iterator

Referenced by reset().

Here is the caller graph for this function:

◆ begin() [2/2]

graph::const_iterator tbb::flow::interface10::graph::begin ( ) const
inline

start const iterator

Definition at line 839 of file flow_graph.h.

839 { return const_iterator(this, true); }
graph_iterator< const graph, const graph_node > const_iterator

◆ cbegin()

graph::const_iterator tbb::flow::interface10::graph::cbegin ( ) const
inline

start const iterator

Definition at line 843 of file flow_graph.h.

843 { return const_iterator(this, true); }
graph_iterator< const graph, const graph_node > const_iterator

◆ cend()

graph::const_iterator tbb::flow::interface10::graph::cend ( ) const
inline

end const iterator

Definition at line 845 of file flow_graph.h.

845 { return const_iterator(this, false); }
graph_iterator< const graph, const graph_node > const_iterator

◆ decrement_wait_count()

void tbb::flow::interface10::graph::decrement_wait_count ( )
inline

Definition at line 288 of file _flow_graph_impl.h.

288  {
289  release_wait();
290  }
void release_wait() __TBB_override
Deregisters an external entity that may have interacted with the graph.
Definition: flow_graph.h:782

References release_wait().

Here is the call graph for this function:

◆ end() [1/2]

graph::iterator tbb::flow::interface10::graph::end ( )
inline

end iterator

Definition at line 837 of file flow_graph.h.

837 { return iterator(this, false); }
graph_iterator< graph, graph_node > iterator

Referenced by reset().

Here is the caller graph for this function:

◆ end() [2/2]

graph::const_iterator tbb::flow::interface10::graph::end ( ) const
inline

end const iterator

Definition at line 841 of file flow_graph.h.

841 { return const_iterator(this, false); }
graph_iterator< const graph, const graph_node > const_iterator

◆ exception_thrown()

bool tbb::flow::interface10::graph::exception_thrown ( )
inline

Definition at line 385 of file _flow_graph_impl.h.

References caught_exception.

◆ increment_wait_count()

void tbb::flow::interface10::graph::increment_wait_count ( )
inline

Definition at line 284 of file _flow_graph_impl.h.

284  {
285  reserve_wait();
286  }
void reserve_wait() __TBB_override
Used to register that an external entity may still interact with the graph.
Definition: flow_graph.h:775

References reserve_wait().

Here is the call graph for this function:

◆ is_cancelled()

bool tbb::flow::interface10::graph::is_cancelled ( )
inline

return status of graph execution

Definition at line 384 of file _flow_graph_impl.h.

References cancelled.

◆ prepare_task_arena()

void tbb::flow::interface10::graph::prepare_task_arena ( bool  reinit = false)
inlineprivate

Definition at line 254 of file _flow_graph_impl.h.

254  {
255  if (reinit) {
256  __TBB_ASSERT(my_task_arena, "task arena is NULL");
259  }
260  else {
261  __TBB_ASSERT(my_task_arena == NULL, "task arena is not NULL");
263  }
264  if (!my_task_arena->is_active()) // failed to attach
265  my_task_arena->initialize(); // create a new, default-initialized arena
266  __TBB_ASSERT(my_task_arena->is_active(), "task arena is not active");
267  }
Tag class used to indicate the "attaching" constructor.
Definition: task_arena.h:235
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
void initialize()
Forces allocation of the resources for the task_arena as specified in constructor arguments.
Definition: task_arena.h:247

References __TBB_ASSERT, tbb::interface7::task_arena::initialize(), tbb::interface7::task_arena::is_active(), my_task_arena, and tbb::interface7::task_arena::terminate().

Referenced by reset().

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

◆ register_node()

void tbb::flow::interface10::graph::register_node ( graph_node n)
inlineprivate

Definition at line 789 of file flow_graph.h.

789  {
790  n->next = NULL;
791  {
793  n->prev = my_nodes_last;
794  if (my_nodes_last) my_nodes_last->next = n;
795  my_nodes_last = n;
796  if (!my_nodes) my_nodes = n;
797  }
798 }
friend class scoped_lock
Definition: spin_mutex.h:180
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void * lock

◆ release_wait()

void tbb::flow::interface10::graph::release_wait ( )
inlinevirtual

Deregisters an external entity that may have interacted with the graph.

The graph will not return from wait_for_all until all the number of decrement_wait_count calls matches the number of increment_wait_count calls.

Implements tbb::flow::interface10::graph_proxy.

Definition at line 782 of file flow_graph.h.

782  {
783  if (my_root_task) {
786  }
787 }
static void fgt_release_wait(void *)
int decrement_ref_count()
Atomically decrement reference count and returns its new value.
Definition: task.h:761

Referenced by tbb::flow::interface9::gfx_factory::callback(), decrement_wait_count(), and tbb::flow::interface10::async_node< Input, Output, Policy, Allocator >::receiver_gateway_impl::release_wait().

Here is the caller graph for this function:

◆ remove_node()

void tbb::flow::interface10::graph::remove_node ( graph_node n)
inlineprivate

Definition at line 800 of file flow_graph.h.

800  {
801  {
803  __TBB_ASSERT(my_nodes && my_nodes_last, "graph::remove_node: Error: no registered nodes");
804  if (n->prev) n->prev->next = n->next;
805  if (n->next) n->next->prev = n->prev;
806  if (my_nodes_last == n) my_nodes_last = n->prev;
807  if (my_nodes == n) my_nodes = n->next;
808  }
809  n->prev = n->next = NULL;
810 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
friend class scoped_lock
Definition: spin_mutex.h:180
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void * lock

◆ reserve_wait()

void tbb::flow::interface10::graph::reserve_wait ( )
inlinevirtual

Used to register that an external entity may still interact with the graph.

The graph will not return from wait_for_all until a matching number of decrement_wait_count calls is made.

Implements tbb::flow::interface10::graph_proxy.

Definition at line 775 of file flow_graph.h.

775  {
776  if (my_root_task) {
779  }
780 }
void increment_ref_count()
Atomically increment reference count.
Definition: task.h:744
static void fgt_reserve_wait(void *)

Referenced by increment_wait_count(), tbb::flow::interface10::async_node< Input, Output, Policy, Allocator >::receiver_gateway_impl::reserve_wait(), and tbb::flow::interface9::gfx_factory::send_kernel().

Here is the caller graph for this function:

◆ reset()

void tbb::flow::interface10::graph::reset ( reset_flags  f = rf_reset_protocol)
inline

Definition at line 812 of file flow_graph.h.

812  {
813  // reset context
815 
816  if(my_context) my_context->reset();
817  cancelled = false;
818  caught_exception = false;
819  // reset all the nodes comprising the graph
820  for(iterator ii = begin(); ii != end(); ++ii) {
821  graph_node *my_p = &(*ii);
822  my_p->reset_node(f);
823  }
824  // Reattach the arena. Might be useful to run the graph in a particular task_arena
825  // while not limiting graph lifetime to a single task_arena::execute() call.
826  prepare_task_arena( /*reinit=*/true );
828  // now spawn the tasks necessary to start the graph
829  for(task_list_type::iterator rti = my_reset_task_list.begin(); rti != my_reset_task_list.end(); ++rti) {
830  internal::spawn_in_graph_arena(*this, *(*rti));
831  }
832  my_reset_task_list.clear();
833 }
tbb::task_group_context * my_context
void __TBB_EXPORTED_METHOD reset()
Forcefully reinitializes the context after the task tree it was associated with is completed.
graph_iterator< graph, graph_node > iterator
iterator end()
end iterator
Definition: flow_graph.h:837
iterator begin()
start iterator
Definition: flow_graph.h:835
void spawn_in_graph_arena(graph &g, tbb::task &arena_task)
Spawns a task inside graph arena.
void prepare_task_arena(bool reinit=false)

References tbb::flow::interface10::internal::activate_graph(), begin(), cancelled, caught_exception, tbb::flow::interface10::internal::deactivate_graph(), end(), my_context, my_reset_task_list, prepare_task_arena(), tbb::task_group_context::reset(), tbb::flow::interface10::graph_node::reset_node(), and tbb::flow::interface10::internal::spawn_in_graph_arena().

Here is the call graph for this function:

◆ root_task()

tbb::task* tbb::flow::interface10::graph::root_task ( )
inline

Returns the root task of the graph.

Definition at line 357 of file _flow_graph_impl.h.

357  {
358  return my_root_task;
359  }

References my_root_task.

Referenced by tbb::flow::interface10::source_node< Output >::create_put_task(), tbb::flow::interface10::limiter_node< T >::forward_task(), tbb::flow::interface10::limiter_node< T >::register_predecessor(), tbb::flow::interface10::limiter_node< T >::register_successor(), run(), and tbb::flow::interface10::limiter_node< T >::try_put_task().

Here is the caller graph for this function:

◆ run() [1/2]

template<typename Receiver , typename Body >
void tbb::flow::interface10::graph::run ( Receiver &  r,
Body  body 
)
inline

Spawns a task that runs a body and puts its output to a specific receiver.

The task is spawned as a child of the graph. This is useful for running tasks that need to block a wait_for_all() on the graph. For example a one-off source.

Definition at line 306 of file _flow_graph_impl.h.

306  {
307  if (internal::is_graph_active(*this)) {
308  task* rtask = new (task::allocate_additional_child_of(*root_task()))
309  run_and_put_task< Receiver, Body >(r, body);
310  my_task_arena->execute(spawn_functor(*rtask));
311  }
312  }
internal::return_type_or_void< F >::type execute(F &f)
Definition: task_arena.h:342
tbb::task * root_task()
Returns the root task of the graph.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task * task

References tbb::interface7::task_arena::execute(), tbb::flow::interface10::internal::is_graph_active(), my_task_arena, and root_task().

Here is the call graph for this function:

◆ run() [2/2]

template<typename Body >
void tbb::flow::interface10::graph::run ( Body  body)
inline

Spawns a task that runs a function object.

The task is spawned as a child of the graph. This is useful for running tasks that need to block a wait_for_all() on the graph. For example a one-off source.

Definition at line 318 of file _flow_graph_impl.h.

318  {
319  if (internal::is_graph_active(*this)) {
320  task* rtask = new (task::allocate_additional_child_of(*root_task())) run_task< Body >(body);
321  my_task_arena->execute(spawn_functor(*rtask));
322  }
323  }
internal::return_type_or_void< F >::type execute(F &f)
Definition: task_arena.h:342
tbb::task * root_task()
Returns the root task of the graph.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task * task

References tbb::interface7::task_arena::execute(), tbb::flow::interface10::internal::is_graph_active(), my_task_arena, and root_task().

Here is the call graph for this function:

◆ wait_for_all()

void tbb::flow::interface10::graph::wait_for_all ( )
inline

Wait until graph is idle and decrement_wait_count calls equals increment_wait_count calls.

The waiting thread will go off and steal work while it is block in the wait_for_all.

Definition at line 327 of file _flow_graph_impl.h.

327  {
328  cancelled = false;
329  caught_exception = false;
330  if (my_root_task) {
331 #if TBB_USE_EXCEPTIONS
332  try {
333 #endif
334  my_task_arena->execute(wait_functor(my_root_task));
336 #if TBB_USE_EXCEPTIONS
337  }
338  catch (...) {
340  my_context->reset();
341  caught_exception = true;
342  cancelled = true;
343  throw;
344  }
345 #endif
346  // TODO: the "if" condition below is just a work-around to support the concurrent wait
347  // mode. The cancellation and exception mechanisms are still broken in this mode.
348  // Consider using task group not to re-implement the same functionality.
350  my_context->reset(); // consistent with behavior in catch()
352  }
353  }
354  }
internal::return_type_or_void< F >::type execute(F &f)
Definition: task_arena.h:342
tbb::task_group_context * my_context
void __TBB_EXPORTED_METHOD reset()
Forcefully reinitializes the context after the task tree it was associated with is completed.
bool __TBB_EXPORTED_METHOD is_group_execution_cancelled() const
Returns true if the context received cancellation request.
void set_ref_count(int count)
Set reference count.
Definition: task.h:734
uintptr_t traits() const
Returns the context's trait.
Definition: task.h:555

References cancelled, caught_exception, tbb::task_group_context::concurrent_wait, tbb::interface7::task_arena::execute(), tbb::task_group_context::is_group_execution_cancelled(), my_context, my_root_task, my_task_arena, tbb::task_group_context::reset(), tbb::task::set_ref_count(), and tbb::task_group_context::traits().

Referenced by ~graph().

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

Friends And Related Function Documentation

◆ async_node

template<typename Input , typename Output , typename Policy , typename Allocator >
friend class async_node
friend

Definition at line 419 of file _flow_graph_impl.h.

◆ graph_iterator

template<typename C , typename N >
friend class graph_iterator
friend

Definition at line 363 of file _flow_graph_impl.h.

◆ graph_node

friend class graph_node
friend

Definition at line 201 of file _flow_graph_impl.h.

◆ internal::activate_graph

◆ internal::add_task_to_graph_reset_list

◆ internal::deactivate_graph

◆ internal::execute_in_graph_arena

template<typename F >
void internal::execute_in_graph_arena ( graph g,
F &  f 
)
friend

◆ internal::is_graph_active

bool internal::is_graph_active ( graph g)
friend

◆ internal::spawn_in_graph_arena

void internal::spawn_in_graph_arena ( graph g,
tbb::task arena_task 
)
friend

◆ tbb::interface7::internal::task_arena_base

Definition at line 422 of file _flow_graph_impl.h.

Member Data Documentation

◆ cancelled

bool tbb::flow::interface10::graph::cancelled
private

Definition at line 394 of file _flow_graph_impl.h.

Referenced by is_cancelled(), reset(), and wait_for_all().

◆ caught_exception

bool tbb::flow::interface10::graph::caught_exception
private

Definition at line 395 of file _flow_graph_impl.h.

Referenced by exception_thrown(), reset(), and wait_for_all().

◆ my_context

tbb::task_group_context* tbb::flow::interface10::graph::my_context
private

Definition at line 392 of file _flow_graph_impl.h.

Referenced by reset(), and wait_for_all().

◆ my_is_active

◆ my_nodes

graph_node* tbb::flow::interface10::graph::my_nodes
private

◆ my_nodes_last

graph_node * tbb::flow::interface10::graph::my_nodes_last
private

◆ my_priority_queue

internal::graph_task_priority_queue_t tbb::flow::interface10::graph::my_priority_queue
private

◆ my_reset_task_list

task_list_type tbb::flow::interface10::graph::my_reset_task_list
private

◆ my_root_task

tbb::task* tbb::flow::interface10::graph::my_root_task
private

◆ my_task_arena

tbb::task_arena* tbb::flow::interface10::graph::my_task_arena
private

◆ nodelist_mutex

◆ own_context

bool tbb::flow::interface10::graph::own_context
private

Definition at line 393 of file _flow_graph_impl.h.


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

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.