Back to Taskflow

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

docs/classtf_1_1RandomPartitioner.html

4.0.03.2 KB
Original Source

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

class to construct a random partitioner for scheduling parallel algorithms

Template parameters
C

Similar to tf::DynamicPartitioner, the partitioner splits iterations into many partitions but each with a random chunk size in the range, c = [alpha * N * W, beta * N * W]. By default, alpha is 0.01 and beta is 0.5, respectively.

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

RandomPartitioner() defaulteddefault constructorRandomPartitioner(size_t sz) explicit construct a dynamic partitioner with the given chunk sizeRandomPartitioner(size_t sz, C&& closure) explicit construct a random partitioner with the given chunk size and the closureRandomPartitioner(float alpha, float beta)constructs a random partitioner with the given parametersRandomPartitioner(float alpha, float beta, C&& closure)constructs a random partitioner with the given parameters and the closure

Public functions

auto alpha() const -> floatqueries the alpha valueauto beta() const -> floatqueries the beta valueauto chunk_size_range(size_t N, size_t W) const -> std::pair<size_t, size_t>queries the range of chunk size

Function documentation

template<typename C> std::pair<size_t, size_t> tf::RandomPartitioner<C>::chunk_size_range(size_t N, size_t W) const

queries the range of chunk size

Parameters
N
W