|
1 load(libdir + "parallelarray-helpers.js"); |
|
2 |
|
3 // Tests that reduce saves its intermediate state correctly by |
|
4 // inducing a bailout in the middle of the reduction. This test may |
|
5 // fail to test what it is intended to test if the wrong number of |
|
6 // worker threads etc are present. It reproduced an existing bug when |
|
7 // used with 8 worker threads. |
|
8 |
|
9 function testReduce() { |
|
10 var aCounter = 0; |
|
11 function sum(a, b) { |
|
12 var r = a + b; |
|
13 if (r == 234) // occurs once per slice |
|
14 aCounter++; |
|
15 return r; |
|
16 } |
|
17 |
|
18 // We use a big array, to make sure that the test runs with 64 slices. |
|
19 var array = build(8 * 4096, function() { return 1; }); |
|
20 var seqResult = array.reduce(sum); |
|
21 var seqCounter = aCounter; |
|
22 |
|
23 aCounter = 0; |
|
24 var parResult = array.reducePar(sum); |
|
25 var parCounter = aCounter; |
|
26 |
|
27 assertEq(true, parCounter >= seqCounter); |
|
28 assertStructuralEq(parResult, seqResult); |
|
29 } |
|
30 |
|
31 if (getBuildConfiguration().parallelJS) |
|
32 testReduce(); |