Bug 14886 – [REG2.066] std.parallelism.parallel with large static array seems to hang compile
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-07T18:49:00Z
Last change time
2017-08-02T08:07:27Z
Keywords
performance, pull
Assigned to
nobody
Creator
schveiguy
Comments
Comment #0 by schveiguy — 2015-08-07T18:49:24Z
example:
import std.parallelism;
void main()
{
int x[100_000];
parallel(x);
}
If you remove one 0 from the number of elements, the compile finishes with an error:
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d-mixin-3780(3878): Error: template std.range.primitives.popFront cannot deduce function from argument types !()(int[10000]), candidates are:
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/range/primitives.d(2032): std.range.primitives.popFront(T)(ref T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[]))
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/range/primitives.d(2055): std.range.primitives.popFront(C)(ref C[] str) if (isNarrowString!(C[]))
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d-mixin-3780(3867): Error: function std.parallelism.ParallelForeach!(int[10000]).ParallelForeach.opApply.doIt.makeTemp no return exp; or assert(0); at end of function
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d-mixin-3792(3890): Error: template std.range.primitives.popFront cannot deduce function from argument types !()(int[10000]), candidates are:
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/range/primitives.d(2032): std.range.primitives.popFront(T)(ref T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[]))
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/range/primitives.d(2055): std.range.primitives.popFront(C)(ref C[] str) if (isNarrowString!(C[]))
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d-mixin-3792(3879): Error: function std.parallelism.ParallelForeach!(int[10000]).ParallelForeach.opApply.doIt.makeTemp no return exp; or assert(0); at end of function
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d(3303): Error: template instance std.parallelism.ParallelForeach!(int[10000]) error instantiating
testarray.d(6): instantiated from here: parallel!(int[10000])
I'm unsure if this is a bug in the compiler or a bug in std.parallelism. I don't know how the latter is designed to work, but it does appear that there isn't a valid instantiation for it, so I would suspect a compiler issue.
The timing seems to be non-linear based on the number of elements:
10k elements: 1.5 seconds to reach error
20k elements: 5.2 seconds to reach error
30k elements: 12.2 seconds to reach error
40k elements: 20.9 seconds to reach error
50k elements: 32.9 seconds to reach error
I stopped after that :)
Reduced test case:
@property ref T front(T)(T[] a)
{
return a[0];
}
template ElementType(R)
{
static if (is(typeof(R.init.front.init) T))
alias ElementType = T;
else
alias ElementType = void;
}
void main()
{
alias R = int[100_000];
alias E = ElementType!R;
}
Comment #4 by k.hara.pg — 2015-09-01T10:26:16Z
More:
auto front(T)(T[] a) {}
void main()
{
alias R = int[100_000];
alias E = typeof(front(R.init));
}
Comment #5 by k.hara.pg — 2015-09-16T00:16:48Z
*** Issue 15062 has been marked as a duplicate of this issue. ***