Getting Started Guide
Distributed Computing Examples of
TCP/IP, CORBA, Legion, and Globus
-
TCP/IP
-
CORBA Example
-
Using Legion Tools
-
Using Globus Tools
In this chapter, examples are provided to explain some of the differences
between programming for CORBA, Legion, and Globus. Refer to Methods
for detailed information about these three paradigms.
Note that examples include a prompt (%> or $) that should not be entered.
Variables are indicated with generic name (e.g., yourhost)
and you should enter appropriate information for your site or project.
Optional information is shown in brackets ([ ]).
TCP/IP
The following example demonstrates the use of socket programming. The server
waits for a client to connect and then sends the message "Hello, World!"
to the client. First download the client and server:
Now compile the two files using commands similar to those listed below.
(Note: You have to specify -lsocket -lnsl under Solaris.)
%> cc -o xserver server.c %> cc -o xclient client.c
To try it out, first run the server,
%> xserver
and then from either another window or another machine, run the client
specifying the machine name where the server is running:
%> xclient yourhostname
For more details on socket programming, refer to W. Richard Stevens' UNIX
Network Programming or other UNIX
programming resources.
CORBA Example
As described in Methods, CORBA is a distributed
object system. Each server object supports
an interface, and clients can query the objects according to the interface.
Server objects usually register themselves to a naming service when they
start up. And the clients can query the naming service to get the names
and the object references of the servers.
Now, consider this online bookstore problem. They offer discount books,
but to find what you need, you have to shop around the site by browsing
the web pages. What you really need is a dynamic object infrastructure
to query and report the data you need.
CORBA is particularly suitable for this scenario. Each bookstore registers
its own server object to the naming service, which is running at a central
well-known place. And, a client running at your desktop can query the naming
service to get the bookstores' objects, and query those objects to get
the book information. It is very simple to add more sophisticated query
options, such as the shipping cost if you provide your zip code. If you
decide to buy a book, just invoke another method of the sever object in
CORBA. New bookstores can join the naming service on the fly, or un-bind
the object if they decide to take a vacation. It is a dynamic object system.
Many other systems can be modeled after CORBA as well.
The following is a simple example of server and client. The server program
registers a server object, called "CompServer," which can be invoked to
return a number (price) by its "getData()" method. Several server programs
can run at the same time to register multiple objects to the naming service.
Each can publish its own number. The client program queries the naming
service to get all of the current server objects and invokes the "getData()"
method on each object to get all the numbers, and report those to the user.
Here is the file list. The programs are written in Java.
The ORB (Object Resource Broker) implementation used in this example is
ORBacus 3.2 from Object Oriented Concepts
Incorporation. ORBacus offers CORBA to C++ and Java mapping, and it
runs on multiple platforms. The implementation is free for non-commercial
use and can be downloaded from the website.
More tutorials on CORBA are also available here.
Using Legion Tools
As discussed in Methods, Legion offers
a set of higher-level tools that make transforming
a current application into a distributed one easier. The following examples
are intended to familiarize you with Legion's context space, the
global name space where Legion keeps track of objects and provide you with
some simple examples of Legion commands.
First, you must set up your environment so Legion can function properly
and locate the executable it needs. Run either:
%>. ~user/setup.sh
(for ksh or bash) substituting user with your login
or
%>source ~user/setup.csh
for csh.
Either line can be added to your .cshrc, .kshrc, .bashrc depending on
your shell. Currently, Legion uses passwords for authentication/login.
The login object is your proxy to the world, and Legion generates a certificate
that identifies who you are. Assuming that you have contacted the Legion
administrator at your site and received a password, you can issue the following:
%>legion_login /users/[user id]
where [user id] is your login name.
Now you're ready to try some of the UNIX-like Legion commands to query
Legion's context space. The following command will display various
Legion objects such as host objects, class objects and vaults.
%>legion_ls -l
.
(context)
class (context)
hosts (context)
vaults (context)
home (context)
To see the various host objects, (computers registered with Legion), issue
the following:
%>legion_ls -la /hosts
. (context)
.. (context)
BootstrapHost
bootstrap.host.DNS.name
stonesoup00.cs.virginia.edu
stonesoup03.cs.virginia.edu
Files can be added to Legion in the following two methods:
%>legion_cp -localsrc LocalFileName LegionName
(copies a single file)
%>legion_import_tree LocalDirectoryName LegionContextSpace
(copies entire UNIX directory structure into context space)
Many other Legion commands exist including: legion_mkdir, legion_ln,
legion_whereis,
legion_object_info . For more information, issue:
%>man [legion command]
Legion enables you to run both sequential and parallel (MPI) programs.
Legion provides tools for compiling a program and registering it for multiple
architectures. The following will register the UNIX cp as the Legion
object "Copy" under the Linux platform.
%>legion_register_program Copy /bin/cp linux
Program class "Copy" does not exist.
Creating class "Copy".
Registering implementation for class "Copy".
Now, the program Copy can be executed on a remote Linux system:
%>legion_run -in /dir1/src -out /dir2/dest Copy src dest
The -in option tells Legion to copy the Legion file /dir1/src into the
remote program's Copy's current working directory and call it "src". After
Copy executes, "src" is copied to the Legion file object "dest". Finally,
"dest" is copied to a local UNIX file "/dir2/dest".
Additional options to the legion_run command allow users to specify
which architectures or hosts to run the executable on. Parallel programs
written using MPI can be registered using legion_mpi_register.
legion_mpi_register mpi_app ~/bin/solaris/mpi_app solaris
"/mpi/programs/mpi_app" does not exist - creating it "/mpi/instances/mpi_app"
does not exist - creating it
The Legion command legion_mpi_run is used to execute an MPI executable.
legion_mpi_run -v -n 3 -HF HostFile mpi/programs/mpi_app
The options -n and -HF can be used to specify the number of processors
to use and/or a "HostFile" containing the names of hosts and processors
to be used. In this example, HostFile might look like:
/hosts/centurion241 2
/hosts/centurion242 2
/hosts/centurion243 2
More on-line Legion tutorials can be found on
the Legion website.
Using Globus Tools
Globus, like Legion, also provides a set of higher-level tools to allow
you to generate a certificate, stage files, run programs on remote machines,
and find out static and dynamic information about various machines that
Globus has been deployed on. See Methods for
more information. The examples here will focus on using a few
of the Globus tools.
In order to use Globus, you first need to get a Globus certificate.
Getting a Globus certificate takes several days so allow sufficient time
for this step. See the Globus
Quick Start Guide for more information.
Once you have a valid certificate and have been authorized by the Globus
administrator, you are ready to use Globus. First initialize your proxy,
which is your decrypted private key that authorizes remote processes on
your behalf.
%> grid-proxy-init .....++++++ .........++++++
To access remote resources using Globus, check your directory on a remote
computer by issuing the following command:
%> globus-job-run remotehostname /bin/ls
For example: globus-job-run modi4.ncsa.uiuc.edu /bin/ls runs this
on and NCSA system.
Globus allows more complex job submissions. Below is a sample Resource
Specification Langauage (RSL) file (example.rsl) that can be used:
&(executable=xprog) (count=4) (stdout=output) (queue=globus)
This RSL file specifies the xprog MPI program be run on four processors
in the globus queue and that the stdout output be saved in a file named
output.
This next command submits the specified job:
%> globusrun -f executable.rsl -r
modi4.ncsa.uiuc.edu/jobmanager-lsf
Globus also lets you determine certain characteristics about a particular
machine, a process called resource discovery. Enter the following
command to find out more about the cpuload on an NCSA Origin2000 system:
%> grid-info-search hn=modi4.ncsa.uiuc.edu cpuload1
You can also submit queries about multiple resources by combining filter
operations. For example, you could ask how many processors you could theoretically
use at Argonne National Lab by entering the following:
%>grid-info-search
'(&(hn=*.mcs.anl.gov)(objectclass=GlobusComputeResource))'
cpucount