#parallel #iterator #threads

parallel-iterator

Parallelize any iterator with ease!

7 releases

Uses old Rust 2015

0.1.6 Jul 15, 2020
0.1.5 Aug 24, 2019
0.1.4 Jan 9, 2019
0.1.3 Dec 25, 2018

#104 in Concurrency

Download history 4/week @ 2021-05-26 5/week @ 2021-06-02 12/week @ 2021-06-09 4/week @ 2021-06-16 6/week @ 2021-06-23 6/week @ 2021-06-30 7/week @ 2021-07-07 10/week @ 2021-07-14 3/week @ 2021-07-21 18/week @ 2021-07-28 15/week @ 2021-08-04 12/week @ 2021-08-11 2/week @ 2021-08-18 3/week @ 2021-08-25 1/week @ 2021-09-01 4/week @ 2021-09-08

55 downloads per month
Used in treesum

Apache-2.0/MIT

10KB
93 lines

parallel-iterator

unsafe forbidden

Parallelize any iterator!

Features

  • Support for !Send and !Sync for producer iterators and transform closures. This allows mutable, safe and easy thread local data, using the captured closure environments.
  • Propagates child thread panics.
  • Internal thread handling, don't worry about it! (TODO: make this configurable)

A minimal example

This code is copy-pasted from examples/example_1.rs.

extern crate parallel_iterator;

use parallel_iterator::ParallelIterator;

fn do_some_work(i: u32) -> u32 {
    i + 1 // let's pretend this is a heavy calculation
}

fn main() {
    for i in ParallelIterator::new(|| (0u32..100), || do_some_work) {
    	println!("Got a result: {}!", i);
    }
}

A slightly more realistic example

This code is copy-pasted from examples/example_2.rs.

extern crate parallel_iterator;

use parallel_iterator::ParallelIterator;

fn do_some_work(i: usize, out: &mut Vec<usize>) {
    for j in 0..i {
        out.push(j); // The caller can pre-allocate.
    }
}

fn main() {
    const MAX: usize = 1000;
    let xform_ctor = || {
        let mut buffer = Vec::with_capacity(MAX);
        move |i| {
            buffer.clear(); // Clear but keep the internal allocation.
            do_some_work(i, &mut buffer);
            buffer.last().map(|u| *u) // This is just an example value.
        }
    };
    for i in ParallelIterator::new(|| (0..MAX), xform_ctor) {
        match i {
            Some(i) => println!("Got Some({})!", i),
            None => println!("Got None!"),
        }
    }
}

Please see the documentation on the ParallelIterator struct for more details.

Changelog

0.1.6

  • Updated dependencies.

0.1.5

  • Updated dependencies.

0.1.4

  • Added examples.
  • Improved documentation.
  • Updated dependencies.

0.1.3

  • Switched to crossbeam-channel instead of chan.
  • Updated dependencies.

0.1.2

  • Updated dependencies.

0.1.1

  • Removed dead code in the minimal example.

0.1.0

  • Initial publish.

License

Licensed under either of

at your option.

Dependencies

~445KB