1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/parallel/mandelbrot.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,53 @@ 1.4 +// Adapted from 1.5 +// 1.6 +// https://github.com/RiverTrail/RiverTrail/blob/master/examples/mandelbrot/mandelbrot.js 1.7 +// 1.8 +// which in turn is adapted from a WebCL implementation available at 1.9 +// 1.10 +// http://www.ibiblio.org/e-notes/webcl/mandelbrot.html 1.11 + 1.12 +load(libdir + "parallelarray-helpers.js"); 1.13 + 1.14 +var nc = 30, maxCol = nc*3; 1.15 + 1.16 +// this is the actual mandelbrot computation, ported to JavaScript 1.17 +// from the WebCL / OpenCL example at 1.18 +// http://www.ibiblio.org/e-notes/webcl/mandelbrot.html 1.19 +function computeSetByRow(x, y) { 1.20 + var Cr = (x - 256) / scale + 0.407476; 1.21 + var Ci = (y - 256) / scale + 0.234204; 1.22 + var I = 0, R = 0, I2 = 0, R2 = 0; 1.23 + var n = 0; 1.24 + while ((R2+I2 < 2.0) && (n < 512)) { 1.25 + I = (R+R)*I+Ci; 1.26 + R = R2-I2+Cr; 1.27 + R2 = R*R; 1.28 + I2 = I*I; 1.29 + n++; 1.30 + } 1.31 + return n; 1.32 +} 1.33 + 1.34 +function computeSequentially() { 1.35 + result = []; 1.36 + for (var r = 0; r < rows; r++) { 1.37 + for (var c = 0; c < cols; c++) { 1.38 + result.push(computeSetByRow(r, c)); 1.39 + } 1.40 + } 1.41 + return result; 1.42 +} 1.43 + 1.44 +var scale = 10000*300; 1.45 +var rows = 4; 1.46 +var cols = 4; 1.47 + 1.48 +// check that we get correct result 1.49 +if (getBuildConfiguration().parallelJS) { 1.50 + var expected = computeSequentially(); 1.51 + assertParallelExecSucceeds( 1.52 + function (m) Array.buildPar(rows * cols, function (xy) { 1.53 + return computeSetByRow((xy/cols)|0,(xy%cols)) 1.54 + }, m), 1.55 + function (r) assertStructuralEq(expected, r)); 1.56 +}