Bug 22745 – std.parallelism.parallel fails to process empty range on a single CPU

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-02-07T19:03:26Z
Last change time
2022-12-15T22:48:21Z
Keywords
pull
Assigned to
No Owner
Creator
Steven Schveighoffer

Comments

Comment #0 by schveiguy — 2022-02-07T19:03:26Z
On a VM where I have allocated one core, std.parallelism.parallel fails with the message: workUnitSize must be > 0 This comes from the following code: ```d int main() { import std.stdio; import std.parallelism; int[] arr; foreach(i; arr.parallel) { writeln(i); } } ``` Why does it fail? Here is the code that throws the error: https://github.com/dlang/phobos/blob/ab4008c13f593b35adc7ec2229e299e73c182930/std/parallelism.d#L1631 Note that the workUnitSize is passed in from the default work unit size. That is determined via this function: https://github.com/dlang/phobos/blob/ab4008c13f593b35adc7ec2229e299e73c182930/std/parallelism.d#L1631 The `size` value is set determined by the number of cores here: https://github.com/dlang/phobos/blob/ab4008c13f593b35adc7ec2229e299e73c182930/std/parallelism.d#L1524 Note that if "size" is zero (having 1 core), and the range is zero length, then the workUnitSize will be zero. I'd suspect a fix is to check if the range is empty and immediately return before getting this far.
Comment #1 by dlang-bot — 2022-11-30T21:33:50Z
@kinke created dlang/phobos pull request #8633 "[stable] Fix Issue 22745 - std.parallelism.parallel fails to process empty range on a single CPU" fixing this issue: - Fix Issue 22745 - std.parallelism.parallel fails to process empty range on a single CPU https://github.com/dlang/phobos/pull/8633
Comment #2 by dlang-bot — 2022-12-01T10:49:24Z
dlang/phobos pull request #8633 "[stable] Fix Issue 22745 - std.parallelism.parallel fails to process empty range on a single CPU" was merged into stable: - ded657505ceec063163790b5c925ce31baca2b6f by Martin Kinkelin: Fix Issue 22745 - std.parallelism.parallel fails to process empty range on a single CPU https://github.com/dlang/phobos/pull/8633
Comment #3 by dlang-bot — 2022-12-15T22:48:21Z
dlang/phobos pull request #8650 "merge stable" was merged into master: - 5645d87eb165be79d49d54cd9ccdce921c5229a9 by Martin Kinkelin: Fix Issue 22745 - std.parallelism.parallel fails to process empty range on a single CPU https://github.com/dlang/phobos/pull/8650