incubator-hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Hama Wiki] Trivial Update of "Architecture" by edwardyoon
Date Tue, 12 Oct 2010 01:33:28 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Hama Wiki" for change notification.

The "Architecture" page has been changed by edwardyoon.
The comment on this change is: trivial change.
http://wiki.apache.org/hama/Architecture?action=diff&rev1=130&rev2=131

--------------------------------------------------

     * One task acts as master and collects the results.
  
  {{{
+ public class PiEstimator {
+   private static String MASTER_TASK = "master.task.";
+ 
+   public static class MyEstimator extends BSP {
+     public static final Log LOG = LogFactory.getLog(MyEstimator.class);
+     private Configuration conf;
+     private String masterTask;
+     private static final int iterations = 10000;
+ 
      public void bsp(BSPPeer bspPeer) throws IOException, KeeperException,
          InterruptedException {
        int in = 0, out = 0;
@@ -154, +163 @@

        byte[] myData = Bytes.toBytes(4.0 * (double) in / (double) iterations);
        BSPMessage estimate = new BSPMessage(tagName, myData);
  
+       bspPeer.send(bspPeer.getAddress(masterTask), estimate);
-       Log.info("Send a message (" + Bytes.toDouble(myData) + ") from "
-           + bspPeer.getServerName() + " to localhost:30000");
-       bspPeer.send(new InetSocketAddress("localhost", 30000), estimate);
        bspPeer.sync();
  
        double pi = 0.0;
@@ -169, +176 @@

          System.out.println("Estimated value of PI is " + pi);
  
      }
+ 
+     @Override
+     public Configuration getConf() {
+       return conf;
+     }
+ 
+     @Override
+     public void setConf(Configuration conf) {
+       this.conf = conf;
+       this.masterTask = conf.get(MASTER_TASK);
+     }
+ 
+   }
+ 
+   public static void main(String[] args) throws InterruptedException,
+       IOException {
+     // BSP job configuration
+     HamaConfiguration conf = new HamaConfiguration();
+     // Execute locally
+     // conf.set("bsp.master.address", "local");
+ 
+     BSPJob bsp = new BSPJob(conf, PiEstimator.class);
+     // Set the job name
+     bsp.setJobName("pi estimation example");
+     bsp.setBspClass(MyEstimator.class);
+ 
+     BSPJobClient jobClient = new BSPJobClient(conf);
+     ClusterStatus cluster = jobClient.getClusterStatus(true);
+     // Choose one as a master
+     for (String name : cluster.getActiveGroomNames()) {
+       conf.set(MASTER_TASK, name);
+       break;
+     }
+ 
+     BSPJobClient.runJob(bsp);
+   }
+ }
  }}}
  

Mime
View raw message