Return-Path: X-Original-To: apmail-hama-commits-archive@www.apache.org Delivered-To: apmail-hama-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B78A211C2C for ; Thu, 22 May 2014 09:07:49 +0000 (UTC) Received: (qmail 38941 invoked by uid 500); 22 May 2014 09:07:49 -0000 Delivered-To: apmail-hama-commits-archive@hama.apache.org Received: (qmail 38907 invoked by uid 500); 22 May 2014 09:07:49 -0000 Mailing-List: contact commits-help@hama.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hama.apache.org Delivered-To: mailing list commits@hama.apache.org Received: (qmail 38899 invoked by uid 99); 22 May 2014 09:07:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 May 2014 09:07:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 May 2014 09:07:49 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4457223888E4; Thu, 22 May 2014 09:07:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1596782 - in /hama/trunk: CHANGES.txt examples/src/main/java/org/apache/hama/examples/PiEstimator.java Date: Thu, 22 May 2014 09:07:25 -0000 To: commits@hama.apache.org From: millecker@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140522090725.4457223888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: millecker Date: Thu May 22 09:07:24 2014 New Revision: 1596782 URL: http://svn.apache.org/r1596782 Log: HAMA-905: Fix Pi Estimator Example Modified: hama/trunk/CHANGES.txt hama/trunk/examples/src/main/java/org/apache/hama/examples/PiEstimator.java Modified: hama/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hama/trunk/CHANGES.txt?rev=1596782&r1=1596781&r2=1596782&view=diff ============================================================================== --- hama/trunk/CHANGES.txt (original) +++ hama/trunk/CHANGES.txt Thu May 22 09:07:24 2014 @@ -8,6 +8,7 @@ Release 0.7.0 (unreleased changes) BUG FIXES + HAMA-905: Fix Pi Estimator Example (Martin Illecker) HAMA-889: NonDefaultIterator of DenseDoubleVector never reaches the end (Yexi Jiang) HAMA-888: Add more test cases for DenseDoubleVector (Yexi Jiang) HAMA-885: Semi-Clustering is not producing expected output (Renil J via edwardyoon) Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/PiEstimator.java URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/PiEstimator.java?rev=1596782&r1=1596781&r2=1596782&view=diff ============================================================================== --- hama/trunk/examples/src/main/java/org/apache/hama/examples/PiEstimator.java (original) +++ hama/trunk/examples/src/main/java/org/apache/hama/examples/PiEstimator.java Thu May 22 09:07:24 2014 @@ -27,6 +27,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IOUtils; +import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.io.Text; import org.apache.hama.HamaConfiguration; @@ -46,33 +47,32 @@ public class PiEstimator { + System.currentTimeMillis()); public static class MyEstimator extends - BSP { + BSP { public static final Log LOG = LogFactory.getLog(MyEstimator.class); private String masterTask; private static final int iterations = 10000; @Override public void bsp( - BSPPeer peer) + BSPPeer peer) throws IOException, SyncException, InterruptedException { - int in = 0; + long in = 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)) { + double x = 2.0 * Math.random() - 1.0; // [-1..1] + double y = 2.0 * Math.random() - 1.0; // [-1..1] + if ((x * x + y * y) <= 1.0) { in++; } } - double data = 4.0 * in / iterations; - - peer.send(masterTask, new DoubleWritable(data)); + peer.send(masterTask, new LongWritable(in)); peer.sync(); } @Override public void setup( - BSPPeer peer) + BSPPeer peer) throws IOException { // Choose one as a master this.masterTask = peer.getPeerName(peer.getNumPeers() / 2); @@ -80,17 +80,17 @@ public class PiEstimator { @Override public void cleanup( - BSPPeer peer) + BSPPeer peer) throws IOException { if (peer.getPeerName().equals(masterTask)) { - double pi = 0.0; + long in = 0; int numPeers = peer.getNumCurrentMessages(); - DoubleWritable received; + LongWritable received; while ((received = peer.getCurrentMessage()) != null) { - pi += received.get(); + in += received.get(); } + double pi = 4.0 * in / (iterations * numPeers); - pi = pi / numPeers; peer.write(new Text("Estimated value of PI is"), new DoubleWritable(pi)); } } @@ -119,7 +119,7 @@ public class PiEstimator { BSPJob bsp = new BSPJob(conf, PiEstimator.class); bsp.setCompressionCodec(SnappyCompressor.class); bsp.setCompressionThreshold(40); - + // Set the job name bsp.setJobName("Pi Estimation Example"); bsp.setBspClass(MyEstimator.class);