Back to Taskflow

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

docs/classtf_1_1GuidedPartitioner.html

4.0.02.1 KB
Original Source

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

class to create a guided partitioner for scheduling parallel algorithms

Template parameters
C

The size of a partition is proportional to the number of unassigned iterations divided by the number of workers, and the size will gradually decrease to the given chunk size. The last partition may be smaller than the chunk size.

In addition to partition size, the application can specify a closure wrapper for a guided 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::GuidedPartitioner(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

GuidedPartitioner() defaulteddefault constructorGuidedPartitioner(size_t sz) explicit construct a guided partitioner with the given chunk sizeGuidedPartitioner(size_t sz, C&& closure) explicit construct a guided partitioner with the given chunk size and the closure