Skip to content

Commit 0fd9607

Browse files
authored
Merge pull request #50 from orxfun/redesigning-parallel-traits
Redesigning parallel traits
2 parents be3d691 + 0e15e58 commit 0fd9607

File tree

220 files changed

+12556
-12906
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+12556
-12906
lines changed

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
toolchain: ["stable"]
19+
features: ["", "--features generic_iterator"]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Install toolchain
25+
uses: dtolnay/rust-toolchain@master
26+
with:
27+
toolchain: ${{ matrix.toolchain }}
28+
29+
- name: Install 32bit target
30+
run: rustup target add i686-unknown-linux-musl
31+
- name: Install wasm target
32+
run: rustup target add wasm32-unknown-unknown
33+
- name: Install miri
34+
run: rustup component add --toolchain nightly-x86_64-unknown-linux-gnu miri
35+
- name: Install no-std-check
36+
run: cargo install cargo-no-std-check
37+
38+
- name: Build
39+
run: cargo build --verbose ${{ matrix.features }}
40+
- name: Build-32bit
41+
run: cargo build --verbose --target i686-unknown-linux-musl ${{ matrix.features }}
42+
- name: Build-wasm
43+
run: cargo build --verbose --target wasm32-unknown-unknown ${{ matrix.features }}
44+
45+
- name: Test
46+
run: cargo test --verbose ${{ matrix.features }}
47+
- name: Test-32bit
48+
run: cargo test --verbose --target i686-unknown-linux-musl ${{ matrix.features }}
49+
- name: Check-wasm
50+
run: cargo check --verbose --target wasm32-unknown-unknown ${{ matrix.features }}
51+
52+
- name: Clippy
53+
run: cargo clippy ${{ matrix.features }} -- -D warnings --verbose
54+
55+
- name: Miri
56+
run: cargo +nightly miri test --lib --bins --tests --verbose ${{ matrix.features }}

Cargo.toml

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
11
[package]
22
name = "orx-parallel"
3-
version = "1.16.0"
4-
edition = "2021"
3+
version = "2.0.0"
4+
edition = "2024"
55
authors = ["orxfun <[email protected]>"]
6-
description = "A performant and configurable parallel computing library for computations defined as compositions of iterator methods."
6+
readme = "README.md"
7+
description = "High performance, configurable and expressive parallel computation library."
78
license = "MIT OR Apache-2.0"
89
repository = "https://github.com/orxfun/orx-parallel/"
910
keywords = ["parallel", "concurrency", "performance", "thread", "iterator"]
1011
categories = ["concurrency", "algorithms"]
1112

1213
[dependencies]
13-
orx-pseudo-default = { version = "2.0.0", default-features = false }
14-
orx-pinned-vec = "3.15"
15-
orx-fixed-vec = "3.15"
16-
orx-split-vec = "3.15"
17-
orx-pinned-concurrent-col = "2.12"
18-
orx-concurrent-bag = "2.11"
19-
orx-concurrent-ordered-bag = "2.11"
20-
orx-priority-queue = "1.5.0"
21-
orx-concurrent-iter = "1.30.0"
14+
orx-pseudo-default = { version = "2.1.0", default-features = false }
15+
orx-pinned-vec = "3.16.0"
16+
orx-fixed-vec = "3.16.0"
17+
orx-split-vec = "3.16.0"
18+
orx-pinned-concurrent-col = "2.13.0"
19+
orx-concurrent-bag = "2.12.0"
20+
orx-concurrent-ordered-bag = "2.12.0"
21+
orx-iterable = "1.3.0"
22+
orx-priority-queue = "1.7.0"
23+
orx-concurrent-iter = "2.0.0"
24+
rayon = { version = "1.10.0", optional = true }
2225

2326
[dev-dependencies]
2427
chrono = "0.4.39"
28+
clap = { version = "4.5.36", features = ["derive"] }
2529
criterion = "0.5.1"
26-
orx-iterable = "1.2.0"
27-
rand = "0.8"
28-
rand_chacha = "0.3"
30+
orx-concurrent-vec = "3.6.0"
31+
rand = "0.9"
32+
rand_chacha = "0.9"
2933
rayon = "1.10.0"
3034
test-case = "3.3.1"
3135

3236
[[bench]]
33-
name = "flatmap"
37+
name = "reduce_iter_into_par"
3438
harness = false
39+
40+
[features]
41+
default = []
42+
generic_iterator = ["rayon"]

README.md

Lines changed: 207 additions & 152 deletions
Large diffs are not rendered by default.

benches/all_pairs_dijkstra.rs

Lines changed: 0 additions & 150 deletions
This file was deleted.

benches/collect_filter.rs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
use criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main};
2+
use orx_parallel::*;
3+
use orx_split_vec::SplitVec;
4+
use rand::prelude::*;
5+
use rand_chacha::ChaCha8Rng;
6+
use rayon::iter::IntoParallelIterator;
7+
8+
const TEST_LARGE_OUTPUT: bool = false;
9+
10+
const LARGE_OUTPUT_LEN: usize = match TEST_LARGE_OUTPUT {
11+
true => 64,
12+
false => 0,
13+
};
14+
const SEED: u64 = 5426;
15+
const FIB_UPPER_BOUND: u32 = 201;
16+
17+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
18+
struct Output {
19+
name: String,
20+
numbers: [i64; LARGE_OUTPUT_LEN],
21+
}
22+
23+
fn to_output(idx: &usize) -> Output {
24+
let idx = *idx;
25+
let prefix = match idx % 7 {
26+
0 => "zero-",
27+
3 => "three-",
28+
_ => "sth-",
29+
};
30+
let fib = fibonacci(&(idx as u32));
31+
let name = format!("{}-fib-{}", prefix, fib);
32+
33+
let mut numbers = [0i64; LARGE_OUTPUT_LEN];
34+
for (i, x) in numbers.iter_mut().enumerate() {
35+
*x = match (idx * 7 + i) % 3 {
36+
0 => idx as i64 + i as i64,
37+
_ => idx as i64 - i as i64,
38+
};
39+
}
40+
41+
Output { name, numbers }
42+
}
43+
44+
fn filter(output: &&Output) -> bool {
45+
let last_char = output.name.chars().last().unwrap();
46+
let last_digit: u32 = last_char.to_string().parse().unwrap();
47+
last_digit < 4
48+
}
49+
50+
fn fibonacci(n: &u32) -> u32 {
51+
let mut a = 0;
52+
let mut b = 1;
53+
for _ in 0..*n {
54+
let c = a + b;
55+
a = b;
56+
b = c;
57+
}
58+
a
59+
}
60+
61+
fn inputs(len: usize) -> Vec<Output> {
62+
let mut rng = ChaCha8Rng::seed_from_u64(SEED);
63+
(0..len)
64+
.map(|_| rng.random_range(0..FIB_UPPER_BOUND) as usize)
65+
.map(|x| to_output(&x))
66+
.collect()
67+
}
68+
69+
fn seq(inputs: &[Output]) -> Vec<&Output> {
70+
inputs.iter().filter(filter).collect()
71+
}
72+
73+
fn rayon(inputs: &[Output]) -> Vec<&Output> {
74+
use rayon::iter::ParallelIterator;
75+
inputs.into_par_iter().filter(filter).collect()
76+
}
77+
78+
fn orx_into_vec(inputs: &[Output]) -> Vec<&Output> {
79+
inputs.into_par().filter(filter).collect()
80+
}
81+
82+
fn orx_into_split_vec(inputs: &[Output]) -> SplitVec<&Output> {
83+
inputs.into_par().filter(filter).collect()
84+
}
85+
86+
fn run(c: &mut Criterion) {
87+
let treatments = [65_536, 65_536 * 4];
88+
89+
let mut group = c.benchmark_group("collect_filter");
90+
91+
for n in &treatments {
92+
let input = inputs(*n);
93+
let expected = seq(&input);
94+
let mut sorted = seq(&input);
95+
sorted.sort();
96+
97+
group.bench_with_input(BenchmarkId::new("seq-into-vec", n), n, |b, _| {
98+
assert_eq!(&expected, &seq(&input));
99+
b.iter(|| seq(black_box(&input)))
100+
});
101+
102+
group.bench_with_input(BenchmarkId::new("rayon-into-vec", n), n, |b, _| {
103+
assert_eq!(&expected, &rayon(&input));
104+
b.iter(|| rayon(black_box(&input)))
105+
});
106+
107+
group.bench_with_input(BenchmarkId::new("orx-vec", n), n, |b, _| {
108+
assert_eq!(&expected, &orx_into_vec(&input));
109+
b.iter(|| orx_into_vec(black_box(&input)))
110+
});
111+
112+
group.bench_with_input(BenchmarkId::new("orx-split-vec", n), n, |b, _| {
113+
assert_eq!(&expected, &orx_into_split_vec(&input));
114+
b.iter(|| orx_into_split_vec(black_box(&input)))
115+
});
116+
}
117+
118+
group.finish();
119+
}
120+
121+
criterion_group!(benches, run);
122+
criterion_main!(benches);

0 commit comments

Comments
 (0)