Taskflow  3.2.0-Master-Branch
Loading...
Searching...
No Matches
tf::Task Class Reference

class to create a task handle over a node in a taskflow graph More...

#include <task.hpp>

Public Member Functions

 Task ()=default
 constructs an empty task
 
 Task (const Task &other)
 constructs the task with the copy of the other task
 
Taskoperator= (const Task &)
 replaces the contents with a copy of the other task
 
Taskoperator= (std::nullptr_t)
 replaces the contents with a null pointer
 
bool operator== (const Task &rhs) const
 compares if two tasks are associated with the same graph node
 
bool operator!= (const Task &rhs) const
 compares if two tasks are not associated with the same graph node
 
const std::stringname () const
 queries the name of the task
 
size_t num_successors () const
 queries the number of successors of the task
 
size_t num_dependents () const
 queries the number of predecessors of the task
 
size_t num_strong_dependents () const
 queries the number of strong dependents of the task
 
size_t num_weak_dependents () const
 queries the number of weak dependents of the task
 
Taskname (const std::string &name)
 assigns a name to the task
 
template<typename C >
Taskwork (C &&callable)
 assigns a callable
 
template<typename T >
Taskcomposed_of (T &object)
 creates a module task from a taskflow
 
template<typename... Ts>
Taskprecede (Ts &&... tasks)
 adds precedence links from this to other tasks
 
template<typename... Ts>
Tasksucceed (Ts &&... tasks)
 adds precedence links from other tasks to this
 
Taskrelease (Semaphore &semaphore)
 makes the task release this semaphore
 
Taskacquire (Semaphore &semaphore)
 makes the task acquire this semaphore
 
Taskdata (void *data)
 assigns pointer to user data
 
void reset ()
 resets the task handle to null
 
void reset_work ()
 resets the associated work to a placeholder
 
bool empty () const
 queries if the task handle points to a task node
 
bool has_work () const
 queries if the task has a work assigned
 
template<typename V >
void for_each_successor (V &&visitor) const
 applies an visitor callable to each successor of the task
 
template<typename V >
void for_each_dependent (V &&visitor) const
 applies an visitor callable to each dependents of the task
 
size_t hash_value () const
 obtains a hash value of the underlying node
 
TaskType type () const
 returns the task type
 
void dump (std::ostream &ostream) const
 dumps the task through an output stream
 
void * data () const
 queries pointer to user data
 

Friends

class FlowBuilder
 
class Runtime
 
class Taskflow
 
class TaskView
 
class Executor
 

Detailed Description

class to create a task handle over a node in a taskflow graph

A task is a wrapper over a node in a taskflow graph. It provides a set of methods for users to access and modify the attributes of the associated node in the taskflow graph. A task is very lightweight object (i.e., only storing a node pointer) that can be trivially copied around, and it does not own the lifetime of the associated node.

Member Function Documentation

◆ composed_of()

template<typename T >
Task & tf::Task::composed_of ( T &  object)

creates a module task from a taskflow

Template Parameters
Tobject type
Parameters
objecta custom object that defines T::graph() method
Returns
*this

◆ data()

Task & tf::Task::data ( void *  data)
inline

assigns pointer to user data

Parameters
datapointer to user data

The following example shows how to attach user data to a task and run the task iteratively while changing the data value:

tf::Executor executor;
tf::Taskflow taskflow("attach data to a task");
int data;
// create a task and attach it the data
auto A = taskflow.placeholder();
A.data(&data).work([A](){
auto d = *static_cast<int*>(A.data());
std::cout << "data is " << d << std::endl;
});
// run the taskflow iteratively with changing data
for(data = 0; data<10; data++){
executor.run(taskflow).wait();
}
class to create an executor for running a taskflow graph
Definition executor.hpp:50
tf::Future< void > run(Taskflow &taskflow)
runs a taskflow once
Definition executor.hpp:1573
void * data() const
queries pointer to user data
Definition task.hpp:609
class to create a taskflow object
Definition core/taskflow.hpp:73
T endl(T... args)
Returns
*this

◆ name()

Task & tf::Task::name ( const std::string name)
inline

assigns a name to the task

Parameters
namea std::string acceptable string
Returns
*this

◆ precede()

template<typename... Ts>
Task & tf::Task::precede ( Ts &&...  tasks)

adds precedence links from this to other tasks

Template Parameters
Tsparameter pack
Parameters
tasksone or multiple tasks
Returns
*this

◆ succeed()

template<typename... Ts>
Task & tf::Task::succeed ( Ts &&...  tasks)

adds precedence links from other tasks to this

Template Parameters
Tsparameter pack
Parameters
tasksone or multiple tasks
Returns
*this

◆ work()

template<typename C >
Task & tf::Task::work ( C &&  callable)

assigns a callable

Template Parameters
Ccallable type
Parameters
callablecallable to construct one of the static, dynamic, condition, and cudaFlow tasks
Returns
*this

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