diff -r 000000000000 -r 6474c204b198 js/src/jit-test/tests/parallel/mandelbrot.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/js/src/jit-test/tests/parallel/mandelbrot.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,53 @@ +// Adapted from +// +// https://github.com/RiverTrail/RiverTrail/blob/master/examples/mandelbrot/mandelbrot.js +// +// which in turn is adapted from a WebCL implementation available at +// +// http://www.ibiblio.org/e-notes/webcl/mandelbrot.html + +load(libdir + "parallelarray-helpers.js"); + +var nc = 30, maxCol = nc*3; + +// this is the actual mandelbrot computation, ported to JavaScript +// from the WebCL / OpenCL example at +// http://www.ibiblio.org/e-notes/webcl/mandelbrot.html +function computeSetByRow(x, y) { + var Cr = (x - 256) / scale + 0.407476; + var Ci = (y - 256) / scale + 0.234204; + var I = 0, R = 0, I2 = 0, R2 = 0; + var n = 0; + while ((R2+I2 < 2.0) && (n < 512)) { + I = (R+R)*I+Ci; + R = R2-I2+Cr; + R2 = R*R; + I2 = I*I; + n++; + } + return n; +} + +function computeSequentially() { + result = []; + for (var r = 0; r < rows; r++) { + for (var c = 0; c < cols; c++) { + result.push(computeSetByRow(r, c)); + } + } + return result; +} + +var scale = 10000*300; +var rows = 4; +var cols = 4; + +// check that we get correct result +if (getBuildConfiguration().parallelJS) { + var expected = computeSequentially(); + assertParallelExecSucceeds( + function (m) Array.buildPar(rows * cols, function (xy) { + return computeSetByRow((xy/cols)|0,(xy%cols)) + }, m), + function (r) assertStructuralEq(expected, r)); +}