Back to Taskflow

template<typename C = DefaultClosureWrapper> tf::DynamicPartitioner class

docs/classtf_1_1DynamicPartitioner.html

4.0.02.1 KB
Original Source

template<typename C = DefaultClosureWrapper> tf::DynamicPartitioner class

class to create a dynamic partitioner for scheduling parallel algorithms

Template parameters
C

The partitioner splits iterations into many partitions each of size equal to the given chunk size. Different partitions are distributed dynamically to workers without any specific order.

In addition to partition size, the application can specify a closure wrapper for a dynamic partitioner. A closure wrapper allows the application to wrap a partitioned task (i.e., closure) with a custom function object that performs additional tasks. For example:

std::atomic\<int\> count = 0;tf::Taskflow taskflow;taskflow.for\_each\_index(0, 100, 1, [](){printf("%d\n", i); },tf::DynamicPartitioner(0, [](auto&& closure){// do something before invoking the partitioned task// ...// invoke the partitioned taskclosure();// do something else after invoking the partitioned task// ...});executor.run(taskflow).wait();

Base classes

template<typename C = DefaultClosureWrapper> class PartitionerBase<DefaultClosureWrapper>class to derive a partitioner for scheduling parallel algorithms

Public static functions

static auto type() -> PartitionerType constexprqueries the partition type (dynamic)

Constructors, destructors, conversion operators

DynamicPartitioner() defaulteddefault constructorDynamicPartitioner(size_t sz) explicit construct a dynamic partitioner with the given chunk sizeDynamicPartitioner(size_t sz, C&& closure) explicit construct a dynamic partitioner with the given chunk size and the closure