Crate chili

Source
Expand description

§chili. Rust port of Spice, a low-overhead parallelization library

A crate for very low-overhead fork-join workloads that can potentially be run in parallel.

It works best in cases where there are many small computations and where it is expensive to estimate how many are left on the current branch in order to stop trying to share work across threads.

§Examples

struct Node {
    val: u64,
    left: Option<Box<Node>>,
    right: Option<Box<Node>>,
}

impl Node {
    pub fn tree(layers: usize) -> Self {
        Self {
            val: 1,
            left: (layers != 1).then(|| Box::new(Self::tree(layers - 1))),
            right: (layers != 1).then(|| Box::new(Self::tree(layers - 1))),
        }
    }
}

fn sum(node: &Node, scope: &mut Scope<'_>) -> u64 {
    let (left, right) = scope.join(
        |s| node.left.as_deref().map(|n| sum(n, s)).unwrap_or_default(),
        |s| node.right.as_deref().map(|n| sum(n, s)).unwrap_or_default(),
    );

    node.val + left + right
}

let tree = Node::tree(10);

assert_eq!(sum(&tree, &mut Scope::global()), 1023);

Structs§

  • ThreadPool configuration.
  • A Scoped object that you can run fork-join workloads on.
  • A thread pool for running fork-join workloads.