title: Hamsters.js Returns Erroneous Results
body: <p>Hamsters holds a great promise to my work. <strong>I work with matrices and vectors in JavaScript</strong>. Recently I stumbled upon the JS Multithreading library <strong>Hamsters</strong> and read through the introduction at <a href="https://github.com/austinksmith/Hamsters.js" rel="nofollow">GitHub</a>. Unfortunately I cannot get the code to work right - <strong>usually I don't get any errors but I get wrong or missing results</strong>.... It is extremely important that I get correct results all the time, else I'll have to abandon this approach. Am sure you can help me figure what's wrong. See sample code below. <strong>The Vanilla output is perfectly what I expect but Hamsters doesn't actually return any results, else when/if it does I get erroneous ones</strong> e.g. 0.05681.324987324.602 or similar.</p>
  
  <pre><code>var vec = [0.19560742625827293, 0.5969056836197602, 0.7781011114598421, -1.4801188964351797e-16, 0];
  
          try {
              var i, dotprod = 0, cnt = vec.length;
              for (i = 0; i &lt; cnt; i+=1) {
                  dotprod += (vec[i] * vec[i]);
              }
              console.log("vanilla:" + dotprod);
  
              var params = {'array': vec};
              hamsters.run(params, function () {
                  var arr = params.array;
                  var dotprod = 0;
                  arr.forEach(function (item) {
                      dotprod += (item * item);
                  });
                  console.log("each-thread:" + dotprod);
                  rtn.data = dotprod;
              }, function (output) {
                  console.log("threads:" + output);
              }, hamsters.maxThreads, true, 'Float32');
  
          } catch (err) {
              console.log(err);
          }
  </code></pre>
  
  <p>I've also tried the code below, with the realization that the 'aggregation' means that each thread appends it's subarray into the final output... Still the results are not reliable and even straight out wrong. I have tried it on a matrix this time. The single-threaded Vanilla version still does it perfectly right.</p>
  
  <pre><code>var matrix = [
              [0.19560742625827293, 0.5969056836197602, 0.7781011114598421, -1.4801188964351797e-16, 0],
              [0.19560742625827268, 0.5969056836197597, -0.7781011114598423, 0, -4.9920006143177403e-17],
              [0.6420441782236752, -0.28992643646108446, -0.06100766058506449, 0, 0.7071067811865475],
              [0.3705351281738152, 0.6896295583459146, 0.6221854956882503, 0, 9.114104478471581e-17]
          ];
          var i;
  
          for (i = 0; i &lt; matrix.length; i += 1) {
              try {
                  var j, dotprod = 0, matrix_row = matrix[i];
                  for (j = 0; j &lt; matrix_row.length; j += 1) {
                      dotprod += (matrix_row[j] * matrix_row[j]);
                  }
                  console.log("Vanilla-output:" + dotprod);
  
                  var params = {'array': matrix_row};
                  hamsters.run(params, function () {
                      var arr = params.array;
                      var dotprod = [];
                      arr.forEach(function (item) {
                          dotprod.push(item * item);
                      });
                      //console.log("each-thread:" + dotprod);
                      rtn.data = dotprod;
                  }, function (results) {
                      var output = 0;
                      results.forEach(function (item) {
                          output += item;
                      });
                      console.log("Hamsters-output:" + output);
                  }, hamsters.maxThreads, true, 'Float32');
  
              } catch (err) {
                  console.log(err);
              }
          }
  </code></pre>