Skip to content

Commit

Permalink
Assert non-zero parallel producer mininum length to avoid splittinf o…
Browse files Browse the repository at this point in the history
…ff empty tasks.
  • Loading branch information
adamreichold committed Oct 27, 2021
1 parent f71ec6b commit 4efc563
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/parallel/par.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,14 @@ macro_rules! par_iter_view_wrapper {
where D: Dimension,
A: $($thread_bounds)*,
{
/// Sets the minimum number of elements desired to process in each job. This will not be split any smaller than this length, but of course a producer could already be smaller to begin with.
/// Sets the minimum number of elements desired to process in each job. This will not be
/// split any smaller than this length, but of course a producer could already be smaller
/// to begin with.
///
/// ***Panics*** if `min_len` is zero.
pub fn with_min_len(self, min_len: usize) -> Self {
assert_ne!(min_len, 0, "Minimum number of elements must at least be one to avoid splitting off empty tasks.");

Self {
min_len,
..self
Expand Down Expand Up @@ -306,8 +312,14 @@ impl<D, Parts> Parallel<Zip<Parts, D>>
where
D: Dimension,
{
/// Sets the minimum number of elements desired to process in each job. This will not be split any smaller than this length, but of course a producer could already be smaller to begin with.
/// Sets the minimum number of elements desired to process in each job. This will not be
/// split any smaller than this length, but of course a producer could already be smaller
/// to begin with.
///
/// ***Panics*** if `min_len` is zero.
pub fn with_min_len(self, min_len: usize) -> Self {
assert_ne!(min_len, 0, "Minimum number of elements must at least be one to avoid splitting off empty tasks.");

Self {
min_len,
..self
Expand Down

0 comments on commit 4efc563

Please sign in to comment.