Changes

Jump to: navigation, search

Team Hortons

76 bytes added, 10:15, 15 December 2017
m
Using Join for Divide-and-Conquer Problems
=== Using Join for Divide-and-Conquer Problems ===
Parallel iterators are implemented with a more primitive method called join which takes 2 closures and runs them in parallel. The code snippet below demonstrates quick sort increment algorithm:
<source lang="rust">
 fn quick_sort<T:PartialOrd+Send>increment_all(vslice: &mut [Ti32]) { if vslice.len() <1000 { for p in slice { *p += 1 ; } } else { returnlet mid_point = slice.len() / 2; let (left, right) = slice.split_at_mut(mid_point); rayon::join(|| increment_all(left), || increment_all(right));
}
 
let mid = partition(v);
let (lo, hi) = v.split_at_mut(mid);
rayon::join(|| quick_sort(lo), || quick_sort(hi));
}
</source>
68
edits

Navigation menu