This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No Format
    public void bsp(BSPPeerProtocol bspPeer) throws IOException,
        KeeperException, InterruptedException {
      int in = 0, out = 0;
      for (int i = 0; i < iterations; i++) {
        double x = 2.0 * Math.random() - 1.0, y = 2.0 * Math.random() - 1.0;
        if ((Math.sqrt(x * x + y * y) < 1.0)) {
          in++;
        } else {
          out++;
        }
      }

      byte[] tagName = Bytes.toBytes(bspPeer.getPeerName());
      byte[] myData = Bytes.toBytes(4.0 * (double) in / (double) iterations);
      BSPMessage estimate = new BSPMessage(tagName, myData);

      bspPeer.send(masterTask, estimate);
      bspPeer.sync();


      if (bspPeer.getPeerName().equals(masterTask)) {
        double pi = 0.0;
        int numPeers = bspPeer.getNumCurrentMessages();
        BSPMessage received;
        while ((received = bspPeer.getCurrentMessage()) != null) {
          pi += Bytes.toDouble(received.getData());
      }  }

    if (bspPeer.getPeerName().equals(masterTask)) {         pi = pi / numPeers;
        writeResult(pi);
      }
    }