www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22745] New: std.parallelism.parallel fails to process empty


          Issue ID: 22745
           Summary: std.parallelism.parallel fails to process empty range
                    on a single CPU
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: schveiguy gmail.com

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:

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:


Note that the workUnitSize is passed in from the default work unit size.

That is determined via this function:

The `size` value is set determined by the number of cores here:

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.

Feb 07 2022