docs/classtf_1_1StaticPartitioner.html
class to construct a static partitioner for scheduling parallel algorithms
| Template parameters |
|---|
| C |
The partitioner divides iterations into chunks and distributes chunks to workers in order. If the chunk size is not specified (default 0), the partitioner resorts to a chunk size that equally distributes iterations into workers.
std::vector\<int\> data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}taskflow.for\_each(data.begin(), data.end(), [](int i){}, StaticPartitioner(0));executor.run(taskflow).run();
In addition to partition size, the application can specify a closure wrapper for a static 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::StaticPartitioner(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();
template<typename C = DefaultClosureWrapper> class PartitionerBase<DefaultClosureWrapper>class to derive a partitioner for scheduling parallel algorithms
static auto type() -> PartitionerType constexprqueries the partition type (static)
StaticPartitioner() defaulteddefault constructorStaticPartitioner(size_t sz) explicit construct a static partitioner with the given chunk sizeStaticPartitioner(size_t sz, C&& closure) explicit construct a static partitioner with the given chunk size and the closure
auto adjusted_chunk_size(size_t N, size_t W, size_t w) const -> size_tqueries the adjusted chunk size
queries the adjusted chunk size
Returns the given chunk size if it is not zero, or returns N/W + (w < NW), where N is the number of iterations, W is the number of workers, and w is the worker ID.