Page tree
Skip to end of metadata
Go to start of metadata

Serialize Printing of "Hello BSP"

Each BSP task of the HAMA cluster, will print the string "Hello BSP" in serial order. This example will help you to understand the concepts of the BSP computing model.

  • Each task gets its own hostname (hostname:port pair) and a sorted list containing the hostnames of all the other peers.
  • Each task prints the string "Hello BSP" only when its turn comes at intervals of 5 seconds.

BSP implementation of Serialize Printing of "Hello BSP"

  public class ClassSerializePrinting extends
    BSP<NullWritable, NullWritable, IntWritable, Text> {

  public static final int NUM_SUPERSTEPS = 15;

  @Override
  public void bsp(BSPPeer<NullWritable, NullWritable, IntWritable, Text> bspPeer)
      throws IOException, SyncException, InterruptedException {

    for (int i = 0; i < NUM_SUPERSTEPS; i++) {
      for (String otherPeer : bspPeer.getAllPeerNames()) {
        bspPeer.send(otherPeer, new IntegerMessage(bspPeer.getPeerName(), i));
      }
      bspPeer.sync();
      IntegerMessage msg = null;
      while ((msg = (IntegerMessage) bspPeer.getCurrentMessage()) != null) {
        bspPeer.write(new IntWritable(msg.getData()), new Text(msg.getTag()));
      }
    }
  }
}
  • No labels