Skip to main content

Module task_size

Module task_size 

Source
Expand description

Minimum task sizes for parallel loops.

Handing a slice of work to another worker costs about a microsecond. A task shorter than that loses more to the handoff than it gains.

    min items per task = budget per task / estimated cost per item
  • Loops bound by memory traffic charge one item by the bytes it moves.
  • Loops bound by arithmetic charge one item by a coarse work class.

Charging by bytes is what keeps a floor correct across packing widths. Doubling the scalars in a packed element halves the items a task needs.

§Environment overrides

  • BINIUS_TASK_TARGET_NS sets the time budget per task, in nanoseconds.
  • BINIUS_MIN_TASK_BYTES sets the byte budget per task of a memory-bound loop.

Setting both to 1 floors every loop at one item, which disables the floors for an A/B run.

§Examples

use binius_utils::rayon::prelude::*;
use binius_utils::rayon::task_size::{IndexedParallelIteratorExt, WorkPerItem};

let data = vec![1u64; 1 << 10];

// Memory-bound: one task moves at least the byte budget.
let sum: u64 = data.par_iter().with_min_task_bytes::<u64>().sum();

// Arithmetic-bound: one task runs for at least the time budget.
let max = data.par_iter().with_min_task(WorkPerItem::FieldMuls).max();

assert_eq!((sum, max), (1 << 10, Some(&1)));

Enums§

WorkPerItem
Estimated cost of processing one item of a loop bound by arithmetic.

Traits§

IndexedParallelIteratorExt
Task-size adapters for parallel iterators.

Functions§

min_len_for_bytes
Minimum items per task for a loop whose cost is the bytes it moves.
min_len_for_work
Minimum items per task for a loop bound by arithmetic.
task_chunk_len
Elements per chunk so one chunk spans the byte budget.