Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ assert_eq!(sum, sum2);

`ParThreadPool` implementations of several thread pools are provided in this crate as optional features (see [features](#features) section). Provided that the pool supports scoped computations, it is trivial to implement this trait in most cases (see [implementations](https://github.com/orxfun/orx-parallel/tree/main/src/runner/implementations) for examples).

In most of the cases, *rayon-core*, *scoped_threadpool* and *scoped_pool* perform better than others, and get close to native threads performance with `StdDefaultPool`.

Since parallel computations are generic over the thread pools, performances can be conveniently compared for specific use cases. Such an example benchmark can be found in [collect_filter_map](https://github.com/orxfun/orx-parallel/blob/main/benches/collect_filter_map.rs) file. To have quick tests, you may also use the example [benchmark_pools](https://github.com/orxfun/orx-parallel/blob/main/examples/benchmark_pools.rs).

### ParallelExecutor: chunk size

Once thread pool provides the computation resources, it is [`ParallelExecutor`](https://docs.rs/orx-parallel/latest/orx_parallel/trait.ParallelExecutor)'s task to distribute work to available threads. As mentioned above, all threads receive exactly the same closure. This closure continues to pull elements from the input concurrent iterator and operate on the inputs until all elements are processed.
Expand Down
55 changes: 55 additions & 0 deletions benches/collect_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ fn orx_into_split_vec(inputs: &[Output]) -> SplitVec<&Output> {
inputs.into_par().filter(filter).collect()
}

#[allow(dead_code)]
fn orx_into_vec_with<P: ParThreadPool>(inputs: &[Output], pool: P) -> Vec<&Output> {
inputs.into_par().with_pool(pool).filter(filter).collect()
}

fn run(c: &mut Criterion) {
let treatments = [65_536 * 2];

Expand Down Expand Up @@ -114,6 +119,56 @@ fn run(c: &mut Criterion) {
assert_eq!(&expected, &orx_into_split_vec(&input));
b.iter(|| orx_into_split_vec(black_box(&input)))
});

#[cfg(feature = "rayon-core")]
group.bench_with_input(
BenchmarkId::new("orx-vec (rayon-core::ThreadPool)", n),
n,
|b, _| {
let pool = rayon_core::ThreadPoolBuilder::new()
.num_threads(32)
.build()
.unwrap();
assert_eq!(&expected, &orx_into_vec_with(&input, &pool));
b.iter(|| orx_into_vec_with(black_box(&input), &pool))
},
);

#[cfg(feature = "scoped-pool")]
group.bench_with_input(
BenchmarkId::new("orx-vec (scoped-pool::Pool)", n),
n,
|b, _| {
let pool = scoped_pool::Pool::new(32);
assert_eq!(&expected, &orx_into_vec_with(&input, &pool));
b.iter(|| orx_into_vec_with(black_box(&input), &pool))
},
);

#[cfg(feature = "scoped_threadpool")]
group.bench_with_input(
BenchmarkId::new("orx-vec (scoped_threadpool::Pool)", n),
n,
|b, _| {
let pool = || scoped_threadpool::Pool::new(32);
assert_eq!(&expected, &orx_into_vec_with(&input, pool()));
b.iter(|| orx_into_vec_with(black_box(&input), pool()))
},
);

#[cfg(feature = "yastl")]
group.bench_with_input(BenchmarkId::new("orx-vec (yastl::Pool)", n), n, |b, _| {
let pool = YastlPool::new(32);
assert_eq!(&expected, &orx_into_vec_with(&input, &pool));
b.iter(|| orx_into_vec_with(black_box(&input), &pool))
});

#[cfg(feature = "pond")]
group.bench_with_input(BenchmarkId::new("orx-vec (pond::Pool)", n), n, |b, _| {
let pool = || PondPool::new_threads_unbounded(32);
assert_eq!(&expected, &orx_into_vec_with(&input, pool()));
b.iter(|| orx_into_vec_with(black_box(&input), pool()))
});
}

group.finish();
Expand Down
68 changes: 68 additions & 0 deletions benches/collect_map_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ fn orx_into_split_vec(inputs: &[usize]) -> SplitVec<Output> {
inputs.into_par().map(map).filter(filter).collect()
}

#[allow(dead_code)]
fn orx_into_vec_with<P: ParThreadPool>(inputs: &[usize], pool: P) -> Vec<Output> {
inputs
.into_par()
.with_pool(pool)
.map(map)
.filter(filter)
.collect()
}

fn run(c: &mut Criterion) {
let treatments = [65_536 * 2];

Expand Down Expand Up @@ -113,6 +123,64 @@ fn run(c: &mut Criterion) {
assert_eq!(&expected, &orx_into_split_vec(&input));
b.iter(|| orx_into_split_vec(black_box(&input)))
});

#[cfg(feature = "rayon-core")]
group.bench_with_input(
BenchmarkId::new("orx-into-vec (rayon-core::ThreadPool)", n),
n,
|b, _| {
let pool = rayon_core::ThreadPoolBuilder::new()
.num_threads(32)
.build()
.unwrap();
assert_eq!(&expected, &orx_into_vec_with(&input, &pool));
b.iter(|| orx_into_vec_with(black_box(&input), &pool))
},
);

#[cfg(feature = "scoped-pool")]
group.bench_with_input(
BenchmarkId::new("orx-into-vec (scoped-pool::Pool)", n),
n,
|b, _| {
let pool = scoped_pool::Pool::new(32);
assert_eq!(&expected, &orx_into_vec_with(&input, &pool));
b.iter(|| orx_into_vec_with(black_box(&input), &pool))
},
);

#[cfg(feature = "scoped_threadpool")]
group.bench_with_input(
BenchmarkId::new("orx-into-vec (scoped_threadpool::Pool)", n),
n,
|b, _| {
let pool = || scoped_threadpool::Pool::new(32);
assert_eq!(&expected, &orx_into_vec_with(&input, pool()));
b.iter(|| orx_into_vec_with(black_box(&input), pool()))
},
);

#[cfg(feature = "yastl")]
group.bench_with_input(
BenchmarkId::new("orx-into-vec (yastl::Pool)", n),
n,
|b, _| {
let pool = YastlPool::new(32);
assert_eq!(&expected, &orx_into_vec_with(&input, &pool));
b.iter(|| orx_into_vec_with(black_box(&input), &pool))
},
);

#[cfg(feature = "pond")]
group.bench_with_input(
BenchmarkId::new("orx-into-vec (pond::Pool)", n),
n,
|b, _| {
let pool = || PondPool::new_threads_unbounded(32);
assert_eq!(&expected, &orx_into_vec_with(&input, pool()));
b.iter(|| orx_into_vec_with(black_box(&input), pool()))
},
);
}

group.finish();
Expand Down
57 changes: 57 additions & 0 deletions benches/reduce_iter_into_par.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ fn orx(inputs: &[usize]) -> Option<Output> {
.reduce(reduce)
}

#[allow(dead_code)]
fn orx_with<P: ParThreadPool>(inputs: &[usize], pool: P) -> Option<Output> {
inputs
.into_iter()
.iter_into_par()
.with_pool(pool)
.map(map)
.filter(filter)
.reduce(reduce)
}

fn run(c: &mut Criterion) {
let treatments = [65_536 * 2];

Expand All @@ -116,6 +127,52 @@ fn run(c: &mut Criterion) {
assert_eq!(&expected, &orx(&input));
b.iter(|| orx(black_box(&input)))
});

#[cfg(feature = "rayon-core")]
group.bench_with_input(
BenchmarkId::new("orx (rayon-core::ThreadPool)", n),
n,
|b, _| {
let pool = rayon_core::ThreadPoolBuilder::new()
.num_threads(32)
.build()
.unwrap();
assert_eq!(&expected, &orx_with(&input, &pool));
b.iter(|| orx_with(black_box(&input), &pool))
},
);

#[cfg(feature = "scoped-pool")]
group.bench_with_input(BenchmarkId::new("orx (scoped-pool::Pool)", n), n, |b, _| {
let pool = scoped_pool::Pool::new(32);
assert_eq!(&expected, &orx_with(&input, &pool));
b.iter(|| orx_with(black_box(&input), &pool))
});

#[cfg(feature = "scoped_threadpool")]
group.bench_with_input(
BenchmarkId::new("orx (scoped_threadpool::Pool)", n),
n,
|b, _| {
let pool = || scoped_threadpool::Pool::new(32);
assert_eq!(&expected, &orx_with(&input, pool()));
b.iter(|| orx_with(black_box(&input), pool()))
},
);

#[cfg(feature = "yastl")]
group.bench_with_input(BenchmarkId::new("orx (yastl::Pool)", n), n, |b, _| {
let pool = YastlPool::new(32);
assert_eq!(&expected, &orx_with(&input, &pool));
b.iter(|| orx_with(black_box(&input), &pool))
});

#[cfg(feature = "pond")]
group.bench_with_input(BenchmarkId::new("orx (pond::Pool)", n), n, |b, _| {
let pool = || PondPool::new_threads_unbounded(32);
assert_eq!(&expected, &orx_with(&input, pool()));
b.iter(|| orx_with(black_box(&input), pool()))
});
}

group.finish();
Expand Down