js/src/jit-test/tests/parallel/mandelbrot.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // Adapted from
     2 //
     3 // https://github.com/RiverTrail/RiverTrail/blob/master/examples/mandelbrot/mandelbrot.js
     4 //
     5 // which in turn is adapted from a WebCL implementation available at
     6 //
     7 // http://www.ibiblio.org/e-notes/webcl/mandelbrot.html
     9 load(libdir + "parallelarray-helpers.js");
    11 var nc = 30, maxCol = nc*3;
    13 // this is the actual mandelbrot computation, ported to JavaScript
    14 // from the WebCL / OpenCL example at
    15 // http://www.ibiblio.org/e-notes/webcl/mandelbrot.html
    16 function computeSetByRow(x, y) {
    17   var Cr = (x - 256) / scale + 0.407476;
    18   var Ci = (y - 256) / scale + 0.234204;
    19   var I = 0, R = 0, I2 = 0, R2 = 0;
    20   var n = 0;
    21   while ((R2+I2 < 2.0) && (n < 512)) {
    22     I = (R+R)*I+Ci;
    23     R = R2-I2+Cr;
    24     R2 = R*R;
    25     I2 = I*I;
    26     n++;
    27   }
    28   return n;
    29 }
    31 function computeSequentially() {
    32   result = [];
    33   for (var r = 0; r < rows; r++) {
    34     for (var c = 0; c < cols; c++) {
    35       result.push(computeSetByRow(r, c));
    36     }
    37   }
    38   return result;
    39 }
    41 var scale = 10000*300;
    42 var rows = 4;
    43 var cols = 4;
    45 // check that we get correct result
    46 if (getBuildConfiguration().parallelJS) {
    47   var expected = computeSequentially();
    48   assertParallelExecSucceeds(
    49     function (m) Array.buildPar(rows * cols, function (xy) {
    50       return computeSetByRow((xy/cols)|0,(xy%cols))
    51     }, m),
    52     function (r) assertStructuralEq(expected, r));
    53 }

mercurial