#
#include <taskflow/algorithm/partitioner.hpp>
template<typename C = DefaultClosureWrapper>
tf::PartitionerBase class

class to derive a partitioner for scheduling parallel algorithms

Template parameters
C | closure wrapper type

The class provides base methods to derive a partitioner that can be used to schedule parallel iterations (e.g., tf::Taskflow::for_each).

An partitioner defines the scheduling method for running parallel algorithms, such tf::Taskflow::for_each, tf::Taskflow::reduce, and so on. By default, we provide the following partitioners:

- tf::GuidedPartitioner to enable guided scheduling algorithm of adaptive chunk size
- tf::DynamicPartitioner to enable dynamic scheduling algorithm of equal chunk size
- tf::StaticPartitioner to enable static scheduling algorithm of static chunk size
- tf::RandomPartitioner to enable random scheduling algorithm of random chunk size

Depending on applications, partitioning algorithms can impact the performance a lot. For example, if a parallel-iteration workload contains a regular work unit per iteration, tf::StaticPartitioner can deliver the best performance. On the other hand, if the work unit per iteration is irregular and unbalanced, tf::GuidedPartitioner or tf::DynamicPartitioner can outperform tf::StaticPartitioner. In most situations, tf::GuidedPartitioner can deliver decent performance and is thus used as our default partitioner.

#### Note

Giving the partition size of 0 lets the Taskflow runtime automatically determines the partition size for the given partitioner.

In addition to partition size, the application can specify a closure wrapper for a partitioner. A closure wrapper allows the application to wrapper 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 task
        closure();

        // do something else after invoking the partitioned task
        // ...
      }
    );
    executor.run(taskflow).wait();

#### Note

The default closure wrapper (tf::DefaultClosureWrapper) does nothing but invoke the partitioned task (closure).

## Public types

using closure_wrapper_type = C
  the closure type

## Constructors, destructors, conversion operators

PartitionerBase() defaulted
  default constructor
PartitionerBase(size_t chunk_size) explicit
  construct a partitioner with the given chunk size
PartitionerBase(size_t chunk_size, C&& closure_wrapper)
  construct a partitioner with the given chunk size and closure wrapper

## Public functions

auto chunk_size() const -> size_t
  query the chunk size of this partitioner
void chunk_size(size_t cz)
  update the chunk size of this partitioner
auto closure_wrapper() const -> const C&
  acquire an immutable access to the closure wrapper object
template<typename F>
void closure_wrapper(F&& fn)
  modify the closure wrapper object

## Protected variables

size_t _chunk_size
  chunk size
C _closure_wrapper
  closure wrapper

Tab / T to search, Esc to close
…

Search for symbols, directories, files, pages or modules. You can omit any prefix from the symbol or file path; adding a `:` or `/` suffix lists all members of given symbol or directory.

Use ↓ / ↑ to navigate through the list, Enter to go. Tab autocompletes common prefix, you can copy a link to the result using ⌘ L while ⌘ M produces a Markdown link.

Sorry, nothing was found.