next up previous contents
Next: MPI Interface Up: Message-passing case studies Previous: Message-passing case studies   Contents


Java sockets

The UNIX socket model is most suitable for programming client-server applications. Typical scientific parallel programs do not fit directly into this model. Before a SPMD program can start two conditions must obtain: a pool of symmetric peer processes must have been created, and each peer must be able to address a message to any other. This situation is typically bootstrapped as follows. The program is invoked on one host. This host creates a listening socket. It sends instructions to servers on some other hosts (either explicitly or through a command such as rsh) to start remote invocations of the program (somehow sending the number of the port on which it is listening in the initiation message). Each new process creates a listening socket and sends its port number to the original process. The original process broadcasts these address to all its slaves. At this point each process knows the port number on which each of its peers is listening. Either they establish all-to-all connections now, before entering the SPMD main program, or the main program starts immediately, and connections are established dynamically when a message needs to be sent.

Figure 1: Skeleton of socket-based Life program.
\begin{figure}\footnotesize\begin{verbatim}class life_java {
static public vo...
...hbour sums.
... Update block of board values.
}
}
}\end{verbatim}\end{figure}
Figure 2: Socket-based Life program (detail).
\begin{figure}\footnotesize\begin{verbatim}int sums[][] = new int[blockSize][...
...][y] = 1; break;
default: block[ib][y] = 0; break;
}\end{verbatim}\end{figure}
Figures 1, 2 give a schematic outline of a distributed Life program using java.net. The fairly intricate code sketched above for initialization and establishment of socket connections has been absorbed into the definition of an auxilliary class hpj. Its interface is
  class hpj {
    hpj(String[] args) ;

    int my_id() ;
    int num_processor() ;

    DataInputStream Input(int id) ;
    DataOutputStream Output(int id) ;
    ...
  }
The members Input and Output return streams associated with sockets connected to peer processes. In the example an N by N Life board is divided blockwise in one dimension, each processor holding a local block of width blockSize.

We note

For reasons such as these we suspect that direct socket programming will remain unattractive to scientific parallel programmers, even with the simplified Java socket API.


next up previous contents
Next: MPI Interface Up: Message-passing case studies Previous: Message-passing case studies   Contents
Bryan Carpenter 2002-07-11