
\begin{slide}{Cases}

\begin{center}
{\Large \bf Experiments with ``HPJava''} \\ \vspace{0.25in}
Bryan Carpenter, Yuh-Jye Chang \\
\em Northeast Parallel Architectures Centre, \\
\em Syracuse University, \\
\em Syracuse, New York
\end{center}

\end{slide}

\begin{slide}{Cases}

\begin{center}
\bf Cases for Parallel Java
\end{center}

\small

Analysis 1: {\em Distributed Simulation on the Internet}
\begin{itemize}
\item
Geographically distributed components.
\item
Interacting real and simulated modules (eg, vehicles).
\item
Java as uniform coordination language {\em and} implementation language
for simulation components, including numerically intensive components.
\end{itemize}

\end{slide}

\begin{slide}{Cases}

\begin{center}
\bf Cases for Parallel Java
\end{center}

\small

Analysis 2: {\em Java as a general scientific language}
\begin{itemize}
\item
Java is simple, secure, easy to understand.
\item
Attractive to a wide range of programmers, professional and otherwise.
\item
Easy to analyse, therefore good source language for optimizing compilers (?).
\item
Java takes over from C/C++ as the modern scientific programming language.
\end{itemize}

\end{slide}

\begin{slide}{Options}

\begin{center}
\bf Options to Parallelism in Java
\end{center}

\small

\begin{itemize}
\item
Automatic parallelization (eg, of byte code).
\item
Language extensions?  Directives?  Class libraries?
\item
Fine grain parallelism through extended Java thread mechanism.
Interacting objects.
\item
Task parallelism.  Applets as tasks?  Interacting ``applications''
as tasks?
\item
Tasks started through Web server?  Other Java server?  {\tt rsh}?
\end{itemize}

\end{slide}

\begin{slide}{Options}

\begin{center}
\bf Options to communication in Java
\end{center}

\small

\begin{itemize}
\item
Message-passing.  Communication through Internet sockets?
Communication through higher-level class libraries.  Channels?  MPI?
\item
Communication through shared objects.  Linda-like?  (CORBA-like?)
\item
Data parallelism.  High level ``array syntax'' with implicit
communication (cf A++/P++)?  Explicit collective operations on
distributed arrays (cf Adlib)?
\item
Libraries in Java?  Libraries in native code?
\end{itemize}

\end{slide}

\begin{slide}{NPAC}

\begin{center}
\bf Experiments at NPAC.
\end{center}

\small

\begin{description}
\item{Message passing:}
\begin{itemize}
\item
{\tt java.net} Internet socket interface.
\item
{\em Fortran-M}-like channels.
\item
``Native-methods'' interface to MPICH.
\end{itemize}
\item{Data parallel:}
\begin{itemize}
\item
Classes to describe process arrays and distributed data arrays.
\item
Classes for data traversal (iterators).
\item
Collective communication via operations on distributed arrays:
\verb$shift$, \verb$transpose$, I/O, ...
\end{itemize}
\end{description}
Mainly interacting Java {\em applications}, with applet front-end for
demos.

\end{slide}

\begin{slide}{Message Passing}

\begin{center}
\bf Channel communication
\end{center}

\small

Have implemented a Java class library for {\em channel communication}.
Similar to dynamic channels in Fortran M.

Model attractive because
\begin{itemize}
\item
``Connection oriented'', so maps efficiently onto underlying Internet
socket operations.
\item
Directly supports dynamic situations.  New remote processes (eg, applets)
may come into existence unpredicably.
\item
Layer of abstraction above Internet addresses, socket port numbers,
and resources controlled by Java security model.
\end{itemize}

\end{slide}

\begin{slide}{Message Passing}

\begin{center}
\bf Channel communication
\end{center}

\small

Library supports bi-directional communication of data on a channel.
\begin{itemize}
\item
Pair of locally created channel ends can be connected, creating a local
channel.
\item
A {\em spawn} function starts another Java instance on a remote
processor, and creates an initial channel between parent and child.
\item
Channel ends can be communicated over channels, on similar footing
to data
\item
Functionality similar to ``merge'' in Fortran-M available.
\item
Web applets downloaded from a common server may communicate over a
channel, with server transparently through-routing messages (unimplemented).
\end{itemize}

\end{slide}

\begin{slide}{Message Passing}

\begin{center}
\bf MPI Interface
\end{center}

\small

Experimenting with {\em native methods} interface to MPICH.

Interface modelled on proposed C++ bindings of MPI (but cannot
support derived data types \ldots).
\begin{verbatim}
public class Comm {
  public Comm() ;  // Default constructor:
                   //     equivalent to MPI_COMM_WORLD.

  public int size();
  public int rank();

  public void bSendInt(int [] buf, int dest, int tag);
  public Status recvInt(int [] buf, int source, int tag);

      // ...or whichever primitive types are needed
}
\end{verbatim}
Work in progress.  Simple test cases run, but no full demonstation, yet.

\end{slide}

\begin{slide}{Data Parallel}

\begin{center}
\bf Parallel Arrays in Java
\end{center}

\small

Currently, take a pure class library approach, similar to A++/P++,
HPC++ parallel STL, Adlib, etc.

We parametrize an array by a member of the \verb$Array$ class, similar
to an HPF {\em template}.  Index ranges of array distributed over dimensions
of process grid, represented by \verb$Procs$ class.

Parallel Java application written as a class extending library
class \verb$Node$: maintains some global information and provides
collective operations on arrays.

\end{slide}

\begin{slide}{Data Parallel}

\begin{center}
\bf Data-parallel example: initialization
\end{center}

\small

\begin{verbatim}
  Procs p = new Procs(this, 2, 2) ;

  Range x = new Range(N, p, 0) ;  // distrib over 1st dim of `p'
  Range y = new Range(N, p, 1) ;  // distrib over 2nd dim of `p'

  Array r = new Array(p, x, y) ;

  byte [] w = new byte [r.seg()] ;  // main data array

  ... declare neighbour arrays, `cn_', `cp_', etc, similarly

  // initialize the ``life'' board

  for(r.forall() ; r.test() ; r.next())
    w [r.sub()] = fun(x.idx(), y.idx()) ;
\end{verbatim}

\small

\end{slide}

\begin{slide}{Data Parallel}

\begin{center}
\bf Data-parallel example: main loop
\end{center}

\small

\begin{verbatim}
  for (int k=0; k<NITER; k++) {

    // Get neighbours

    shift(cn_, w, r, 0,  1, CYCLIC);
    shift(cp_, w, r, 0, -1, CYCLIC);
    ... etc, copy arrays for 8 neighbours

    // Life update rule

    for(int i=0; i<w.length; i++) {
      switch (cn_[i] + cp_[i] + c_n[i] + c_p[i] +
              cnn[i] + cnp[i] + cpn[i] + cpp[i]) {
        case 2 : break;
        case 3 : w[i] = 1; break;
        default: w[i] = 0; break;
      }
    }
  }
\end{verbatim}

\end{slide}

\begin{slide}{Data Parallel}

\begin{center}
\bf Data-parallel example: comments
\end{center}

\small

Characteristics of the data-parallel style of programming:
\begin{itemize}
\item
Distribution format of arrays can be changed by altering a few
parameters at start of program (eg, change \verb$Range$ to
\verb$CRange$ for cyclic distribution).  Main program insensitive to
these details.
\item
Low level message-passing abstracted into high-level collective
operations on distributed arrays.
\end{itemize}

Currently the communications in \verb$Node$ are implemented on
\verb$java.net$ sockets.  {\em Plan to provide a ``native-methods'' Java
interface to the full NPAC PCRC library.}

\end{slide}

\begin{slide}{Array Syntax}

\begin{center}
\bf Array syntax in Java.
\end{center}

\small

A higher level approach makes \verb$Array$ classes into true
container classes (for a restricted set of types), and all operations on
arrays collective.
\begin{verbatim}
  ArrayFloat a = new ArrayFloat(p, x, y) ;
  ArrayFloat b = new ArrayFloat(p, x, y) ;
  ArrayInt c = new ArrayInt(p, x, y) ;

  a = MATMUL(b, c) ;
\end{verbatim}
Communication subsumed into collective array operations.  Elements
not accessed directly in the Java program.

Can implement on top of previous SPMD Java array library, {\em or}
by making Java program run as a sequential master program controlling
parallel back end.  Compare with {\em HPF Interpreter},  A++/P++, etc.

Hampered by lack of user-defined operator-overloading in Java.

\end{slide}

