Open nothingnesses opened 2 years ago
Sample program that currently works:
use bitvec::prelude::*;
#[test]
fn parallelism() {
let bits = bits![mut Lsb0, usize; 0; 800];
rayon::scope(|s| {
for (idx, chunk) in bits.chunks_mut(20).enumerate() {
s.spawn(move |_| {
chunk.store(!0u32);
println!("{:02}", idx);
});
}
});
assert!(bits.all());
}
Implementation notes from doing a quick sketch:
impl {Send,Sync}
in bitvec
; should've used that much soonermacro_rules!
.rayon/src/iter/plumbing/mod.rs
and rayon/src/slice/mod.rs
. Bridging to the thread-pool is Rayon's problem, not mine, and they've solved it. The only real logic is in <MyType as Producer>::split_at
; everything else appears to be boilerplate for gluing types together.Questions:
bitvec/src/slice/iter.rs
or just the Rayon ones? Reasons against: it's extra work that they didn't do, so by definition, [bool].rchunks(W).par_iter()
doesn't work and therefore nobody can expect BitSlice.rchunks(W).par_iter()
to work. Reasons for: bitvec
is already a superset of core
, so there's precedent for going above and beyond the source.I probably won't get back to this until, oh, February, so this should serve to restore everything I learned today when I do pick it back up.
It seems rayon has added implementations for RChunks
, although there hasn't yet been a version published on crates.io containing these changes.
I found it easiest to just use bits.as_raw_mut_slice().par_iter_mut()
and manually set bits of the integer storage.
Is there any progress now? Can we implement traits such as FromParallelIterator<bool>
to facilitate more convenient collaboration with Rayon?
let mask = [10.; 100];
let m = mask.par_iter().map(|x| *x > 100.).collect::<BitVec>();
Is there any progress now? Can we implement traits such as
FromParallelIterator<bool>
to facilitate more convenient collaboration with Rayon?let mask = [10.; 100]; let m = mask.par_iter().map(|x| *x > 100.).collect::<BitVec>();
This one has been bugging me, I can iterate in parallel but collecting I'm not sure. Maybe collecting into the underlying T
and then call BitVec::from_vec
?
Currently, code like the following don't work:
But the above works if
vec![false; 100]
is used instead ofbitvec![Lsb0, AtomicUsize; 0; 100]
(orbitvec![0; 100]
), or if.par_iter_mut()
is replaced with.iter_mut()
.It would be great if bitvec had support for rayon to allow its data structures to be iterated through in parallel in a convenient manner (i.e., with rayon's
par_iter()
orpar_iter_mut()
methods). Afaiu, this would require rayon'sParallelIterator
and/orIndexedParallelIterator
traits be implemented for bitvec's types.Fwiw, here is part of a message from @myrrlyn about one way support might be added: