michael@0: load(libdir + "parallelarray-helpers.js"); michael@0: michael@0: // Tests that reduce saves its intermediate state correctly by michael@0: // inducing a bailout in the middle of the reduction. This test may michael@0: // fail to test what it is intended to test if the wrong number of michael@0: // worker threads etc are present. It reproduced an existing bug when michael@0: // used with 8 worker threads. michael@0: michael@0: function testReduce() { michael@0: var aCounter = 0; michael@0: function sum(a, b) { michael@0: var r = a + b; michael@0: if (r == 234) // occurs once per slice michael@0: aCounter++; michael@0: return r; michael@0: } michael@0: michael@0: // We use a big array, to make sure that the test runs with 64 slices. michael@0: var array = build(8 * 4096, function() { return 1; }); michael@0: var seqResult = array.reduce(sum); michael@0: var seqCounter = aCounter; michael@0: michael@0: aCounter = 0; michael@0: var parResult = array.reducePar(sum); michael@0: var parCounter = aCounter; michael@0: michael@0: assertEq(true, parCounter >= seqCounter); michael@0: assertStructuralEq(parResult, seqResult); michael@0: } michael@0: michael@0: if (getBuildConfiguration().parallelJS) michael@0: testReduce();