You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 147 Next »

Hama provides a user-defined function “bsp()” that can be used to write your own BSP program. The bsp() function handles whole parallel part of the program. (It means that the bsp() function is not a iteration part of the program.) It takes one argument, which is a communication protocol interface. (Later, it'll take one more arguments for input data and reporter, and so on.)

Basically, a BSP program consists of a sequence of supersteps. Each superstep consists of the three phases:

  • Local computation
  • Process communication
  • Barrier synchronization

NOTE that these phases should be always sequential order.

Communication

Within bsp() function, you can use the powerful communication functions for many purposes using BSPPeerProtocol. We tried to follow the standard library of BSP world as much as possible. The following table describes all the functions you can use:

Function

Description

send(String peerName, BSPMessage msg)

Send a message to another peer.

put(BSPMessage msg)

Put a message to local queue.

getCurrentMessage()

Get a received message.

getNumCurrentMessages()

Get the number of received messages.

sync()

Barrier synchronization.

getPeerName()

Get a peer name.

getPeerName(int index)

Get a nth peer name.

getNumPeers()

Get the number of peers.

getAllPeerNames()

Get all peer names.

The send(), put() and the other all functions are very flexible. For example, you can send one more messages on to any other processes in bsp() function:

  public void bsp(BSPPeerProtocol bspPeer) throws IOException,
        KeeperException, InterruptedException {
    for (String otherPeer : bspPeer.getAllPeerNames()) {
      String peerName = bspPeer.getPeerName();
      BSPMessage msg = 
        new BSPMessage(Bytes.toBytes(peerName), Bytes.toBytes(“Hi”));
      bspPeer.send(peerName, mgs);
    }
  bspPeer.sync();
}

Synchronization

When all processes have entered the barrier by sync() function, the Hama proceeds to the next superstep. In previous example case, the BSP job will be finished by one synchronization after sending a message “Hi” to all peers.

But, keep in mind that the sync() function not means the end of BSP job. As mentioned previously, the all communication functions are very flexible. For example, the sync() function can be also located in a for loop:

public void bsp(BSPPeerProtocol bspPeer) throws IOException,
  KeeperException, InterruptedException {
    for (int i = 0; i < 100; i++) {
      ….
      bspPeer.sync();
    }
  }

The BSP job will be finished only when all processes have no more local and outgoing queues entries and all processes done. (or killed by user.)

  • No labels