December 9, 2009

Serialize Printing of HelloWorld using BSP of Hama

Apache Hama Team made the BSP package, which is a computational model based on the concept of supersteps on the top of Hadoop for perform matrix/graph computations with better performance. It provide more flexible programming model than Map/Reduce, and more simple APIs than MPI. The vertical system structure of the BSP is as below:



Sequential composition of "supersteps".
- Local computation
- Process Communication
- Barrier Synchronization

* More detailed will be announced very soon.

To helping understand the Synchronization and Superstep, I made a "Serialize Printing of Hello World" example.

The below codes create 10 BSPPeerThreads. Each thread will have a shuffled ID number from 0 to 9.
BSPPeerThread thread;
    int[] randomSequence = new int[] { 2, 3, 4, 5, 0, 1, 6, 7, 8, 9 };
    for (int i = 0; i < NUM_PEER; i++) {
      conf.set("bsp.peers.num", String.valueOf(NUM_PEER));
      conf.set(BSPConstants.PEER_HOST, "localhost");
      conf.set(BSPConstants.PEER_PORT, String
          .valueOf(30000 + randomSequence[i]));
      conf.set(BSPConstants.ZOOKEEPER_SERVER_ADDRS, "localhost:21810");
      thread = new BSPPeerThread(conf, randomSequence[i]);
      thread.start();
      System.out.println(randomSequence[i] + ", " + thread.getName());
      list.add(thread);
    }

    for (int i = 0; i < NUM_PEER; i++) {
      list.get(i).join();
    }

Try to run below codes, then you'll see the output in order of thread ID. (It'll take 10 steps)

for (int i = 0; i < NUM_PEER; i++) {
        if (myId == i) {
          echo.add(getName());
          System.out.println("Hello BSP from " + i + " of " + NUM_PEER + ": "
              + getName());
        }

        try {
          Thread.sleep(2500);
          peer.sync();
        } catch (IOException e) {
          e.printStackTrace();
        } catch (KeeperException e) {
          e.printStackTrace();
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }

2 comments:

  1. Hopefully it will show the best performance and the lowest latency!!

    ReplyDelete