Taskflow  2.4-master-branch
tf::Executor Class Reference

execution interface for running a taskflow graph More...

#include <executor.hpp>

Public Member Functions

 Executor (size_t N=std::thread::hardware_concurrency(), size_t M=cuda_num_devices())
 constructs the executor with N/M cpu/gpu worker threads
 
 Executor (size_t N=std::thread::hardware_concurrency())
 constructs the executor with N worker threads
 
 ~Executor ()
 destructs the executor
 
std::future< void > run (Taskflow &taskflow)
 runs the taskflow once More...
 
template<typename C >
std::future< void > run (Taskflow &taskflow, C &&callable)
 runs the taskflow once and invoke a callback upon completion More...
 
std::future< void > run_n (Taskflow &taskflow, size_t N)
 runs the taskflow for N times More...
 
template<typename C >
std::future< void > run_n (Taskflow &taskflow, size_t N, C &&callable)
 runs the taskflow for N times and then invokes a callback More...
 
template<typename P >
std::future< void > run_until (Taskflow &taskflow, P &&pred)
 runs the taskflow multiple times until the predicate becomes true and then invokes a callback More...
 
template<typename P , typename C >
std::future< void > run_until (Taskflow &taskflow, P &&pred, C &&callable)
 runs the taskflow multiple times until the predicate becomes true and then invokes the callback More...
 
void wait_for_all ()
 wait for all pending graphs to complete
 
size_t num_workers () const
 queries the number of worker threads (can be zero)
 
size_t num_topologies () const
 queries the number of running topologies at the time of this call More...
 
size_t num_domains () const
 queries the number of worker domains More...
 
int this_worker_id () const
 queries the id of the caller thread in this executor More...
 
template<typename Observer , typename... Args>
std::shared_ptr< Observer > make_observer (Args &&... args)
 constructs an observer to inspect the activities of worker threads More...
 
template<typename Observer >
void remove_observer (std::shared_ptr< Observer > observer)
 removes the associated observer
 
size_t num_observers () const
 queries the number of observers
 

Detailed Description

execution interface for running a taskflow graph

An executor object manages a set of worker threads and implements an efficient work-stealing scheduling algorithm to run a taskflow.

Member Function Documentation

◆ make_observer()

template<typename Observer , typename... Args>
std::shared_ptr< Observer > tf::Executor::make_observer ( Args &&...  args)

constructs an observer to inspect the activities of worker threads

Each executor manage a list of observers in shared ownership with callers.

Template Parameters
Observerobserver type derived from tf::ObserverInterface
ArgsT...argument parameter pack
Parameters
argsarguments to forward to the constructor of the observer
Returns
a shared pointer to the created observer

◆ num_domains()

size_t tf::Executor::num_domains ( ) const
inline

queries the number of worker domains

Each domain manages a subset of worker threads to execute domain-specific tasks, for example, HOST tasks and CUDA tasks.

◆ num_topologies()

size_t tf::Executor::num_topologies ( ) const
inline

queries the number of running topologies at the time of this call

When a taskflow is submitted to an executor, a topology is created to store runtime metadata of the running taskflow.

◆ run() [1/2]

std::future< void > tf::Executor::run ( Taskflow taskflow)
inline

runs the taskflow once

Parameters
taskflowa tf::Taskflow object
Returns
a std::future to access the execution status of the taskflow

◆ run() [2/2]

template<typename C >
std::future< void > tf::Executor::run ( Taskflow taskflow,
C &&  callable 
)

runs the taskflow once and invoke a callback upon completion

Parameters
taskflowa tf::Taskflow object
callablea callable object to be invoked after this run
Returns
a std::future to access the execution status of the taskflow

◆ run_n() [1/2]

std::future< void > tf::Executor::run_n ( Taskflow taskflow,
size_t  N 
)
inline

runs the taskflow for N times

Parameters
taskflowa tf::Taskflow object
Nnumber of runs
Returns
a std::future to access the execution status of the taskflow

◆ run_n() [2/2]

template<typename C >
std::future< void > tf::Executor::run_n ( Taskflow taskflow,
size_t  N,
C &&  callable 
)

runs the taskflow for N times and then invokes a callback

Parameters
taskflowa tf::Taskflow
Nnumber of runs
callablea callable object to be invoked after this run
Returns
a std::future to access the execution status of the taskflow

◆ run_until() [1/2]

template<typename P >
std::future< void > tf::Executor::run_until ( Taskflow taskflow,
P &&  pred 
)

runs the taskflow multiple times until the predicate becomes true and then invokes a callback

Parameters
taskflowa tf::Taskflow
preda boolean predicate to return true for stop
Returns
a std::future to access the execution status of the taskflow

◆ run_until() [2/2]

template<typename P , typename C >
std::future< void > tf::Executor::run_until ( Taskflow taskflow,
P &&  pred,
C &&  callable 
)

runs the taskflow multiple times until the predicate becomes true and then invokes the callback

Parameters
taskflowa tf::Taskflow
preda boolean predicate to return true for stop
callablea callable object to be invoked after this run
Returns
a std::future to access the execution status of the taskflow

◆ this_worker_id()

int tf::Executor::this_worker_id ( ) const
inline

queries the id of the caller thread in this executor

Each worker has an unique id from 0 to N-1 exclusive to the associated executor. If the caller thread does not belong to the executor, -1 is returned.


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