You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2011/02/15 06:58:22 UTC
svn commit: r1070782 -
/incubator/hama/trunk/src/examples/org/apache/hama/examples/PiEstimator.java
Author: edwardyoon
Date: Tue Feb 15 05:58:22 2011
New Revision: 1070782
URL: http://svn.apache.org/viewvc?rev=1070782&view=rev
Log:
Trivial refactoring of PI estimator
Modified:
incubator/hama/trunk/src/examples/org/apache/hama/examples/PiEstimator.java
Modified: incubator/hama/trunk/src/examples/org/apache/hama/examples/PiEstimator.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/examples/org/apache/hama/examples/PiEstimator.java?rev=1070782&r1=1070781&r2=1070782&view=diff
==============================================================================
--- incubator/hama/trunk/src/examples/org/apache/hama/examples/PiEstimator.java (original)
+++ incubator/hama/trunk/src/examples/org/apache/hama/examples/PiEstimator.java Tue Feb 15 05:58:22 2011
@@ -64,32 +64,31 @@ public class PiEstimator {
BSPMessage estimate = new BSPMessage(tagName, myData);
bspPeer.send(masterTask, estimate);
- LOG.info("Send message:" + System.currentTimeMillis());
bspPeer.sync();
double pi = 0.0;
+ int numPeers = bspPeer.getNumCurrentMessages();
BSPMessage received;
while ((received = bspPeer.getCurrentMessage()) != null) {
- LOG.info("Receive messages:" + Bytes.toDouble(received.getData())
- + " from " + Bytes.toString(received.getTag()));
- if (pi == 0.0) {
- pi = Bytes.toDouble(received.getData());
- } else {
- pi = (pi + Bytes.toDouble(received.getData())) / 2;
- }
+ pi += Bytes.toDouble(received.getData());
}
- if (pi != 0.0) {
- FileSystem fileSys = FileSystem.get(conf);
-
- SequenceFile.Writer writer = SequenceFile.createWriter(fileSys, conf,
- TMP_OUTPUT, DoubleWritable.class, DoubleWritable.class,
- CompressionType.NONE);
- writer.append(new DoubleWritable(pi), new DoubleWritable(0));
- writer.close();
+ if (bspPeer.getPeerName().equals(masterTask)) {
+ pi = pi / numPeers;
+ writeResult(pi);
}
}
+ private void writeResult(double pi) throws IOException {
+ FileSystem fileSys = FileSystem.get(conf);
+
+ SequenceFile.Writer writer = SequenceFile.createWriter(fileSys, conf,
+ TMP_OUTPUT, DoubleWritable.class, DoubleWritable.class,
+ CompressionType.NONE);
+ writer.append(new DoubleWritable(pi), new DoubleWritable(0));
+ writer.close();
+ }
+
public Configuration getConf() {
return conf;
}