tf::StaticPartitioner class | Taskflow QuickStart

#
template<typename C = DefaultClosureWrapper>
tf::StaticPartitioner class

class to construct a static partitioner for scheduling parallel algorithms

Template parameters
C | closure wrapper type (default tf::DefaultClosureWrapper)

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 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();

## 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 constexpr
  queries the partition type (static)

## Constructors, destructors, conversion operators

StaticPartitioner() defaulted
  default constructor
StaticPartitioner(size_t sz) explicit
  construct a static partitioner with the given chunk size
StaticPartitioner(size_t sz, C&& closure) explicit
  construct a static partitioner with the given chunk size and the closure

## Public functions

auto adjusted_chunk_size(size_t N, size_t W, size_t w) const -> size_t
  queries the adjusted chunk size

## Function documentation

###
template<typename C>
size_t tf::StaticPartitioner<C>::adjusted_chunk_size(size_t N, size_t W, size_t w) const

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.

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.