Java CoG Kit PI Examples for Grid Computing
From Java CoG Kit
Gregor von Laszewski and Guru Prasad
Contents |
Introduction
Grid computing and parallel computing are complex fields within computer science. IN order to simplify the introdcution of students into a selected set of topics we present a small application that is easy to understand, jet has surprisingly some features that make it not trivial. We will be developing a Java based montecarlo program that calculates the value of PI. To our surprise this task has so far not been completed sucessfully by a single student that we assigned this task to. Hence we will develop the approach of succesive refinment to develop a set of programs that perform this task.
We proceed as follows:
- Develop a sequential program in C and Java
- Develop a parallel program in C with MPI
- Develop a server/client based program in Java
- Develop a sequential program in the Java CoG Kit Karajan Workflow language
- Develop a parallel program in the Java CoG Kit Karajan Workflow language while starting a C or a Java program on different nodes of a cluster (e.g. the execute= is to be used)
- Develop a Web Services Solution
All programs developed can be started from the commandline, and have no input. Each program will have an ant or a makefile and clear instructions on compiling and running the examples will be given.
The code and the documentation is maintained in the SVN at the following location ...
Checking out the Code
| Technology | Description | Code | Readme |
| Sequential | An elementary sequential program to calculate PI | sequential-pi.c | README.txt |
| Parallel - MPI | A basic MPI program to compute PI | mpi-pi-a.c mpi-pi-b.c | README.txt |
| Parallel - MPICH | Parallel program to compute PI using MPICH | mpich-pi-a.c | README.txt |
| Parallel - MPIAB (Agents Based MPI) | An elementary prallel program to calculate PI using MPIAB | mpiab-pi-a.java | README.txt |
| WebServices | An elementary SOAP Client and Server to compute PI | MonteCarloPI.java (Server) MonteCarloClient.java (Client) | README.txt |
| Sequential Karajan Workflow | A Karajan Workflow that deploys a sequential PI program on a remote host to compute PI | karajan-sequential-pi.xml | README.txt |
| Parallel Karajan Workflow | A Karajan Workflow that deploys a sequential PI program on multiple hosts to compute PI | karajan-parallel-pi.xml | README.txt |
Statistcs with R
Monte Carlo PI program challenges
- Discussions on Monte Carlo PI program Challenges (.doc)
- Results of PI Program Execution on MPI (.doc)
Sequential Program in C
A sequential program (sequential-pi.c) for computing PI using Monte Carlo makes sequential attempts to hit the dart on the dartboard using a single processor. The program takes as input the following two parameters: This program takes the following input parameters:
- Seed for the random number generator (mandatory).
- Number of attempts to hit the dartboard (mandatory).
Failing to pass the required parameters will cause the program to print the legend (required fields) and terminate.
Installation, Compilation, and Execution
After checking-out the program and the Makefile, one can use the Makefile for the compilation and execution of the program. Makefile displays the appropriate message during compilation and trial execution.
Makefile can be run as a script as shown below:
Makefile
This performs the compilation (cc -o sequential-pi sequential-pi.c) and a trial execution with legend (sequential-pi 10 1000 1).
Parallel Program in C
In the Parallel version of the PI program (mpi-pi-a.c), the number of attempts to hit the dartboard (input by the user) is evenly distributed among all the processors. The successful attempts from each processor is then consolidated to compute the value of PI. It takes as input the following parameters:
- Seed for the random number generator.
- Number of attempts to hit the dartboard.
- Number of processors available to execute the PI program.
Failing to pass these mandatory parameters will result in program termination.
The other version of the mpi-pi program is available at mpi-pi-b.c. The difference between the two versions of the mpi program is in the way the random number generator is seeded and the number of attempts each processor makes to hit the dartboard. We suggest the user to further comprehend these differences. Instalation, Compilation, and Execution instructions holds the same for both the versions.
Installation, Compilation, and Execution
After checking-out the program and the Makefile, one can use the Makefile for the compilation and execution of the program. Makefile displays the appropriate message during compilation and trial execution.
Makefile can be run as a script as shown below:
Makefile
This performs the compilation (mpicc -o mpi-pi-a mpi-pi-a.c) and a trial execution (mpiexec mpi-pi-a 10 1000 3).
MPICH Program in C
Explain why this is the same as the one in the previous section?
This section explains the MPICH (mpi-pi-a.c)version of the parallel pi program. This version of the PI program will be run using MPICH on Windows platform. This depicts another variation of PI program implementation. Instalation, Compilation, and Execution section will explain the steps invovled in installing MPICH. One has to follow these instructions before running the program.
This is exactly similar to the parallel program in C explained in the previous section in terms of the input parameters and the outpt it generates but has implementation differences.
Installation, Compilation, and Execution
MPICH Installation
One can download the binaries from http://www-unix.mcs.anl.gov/mpi/mpich which is the official wesite for MPICH. Follow the installation instructions. All the instructions in this section refers to the MPICH 1.2.4 version and assumes that C:\Program Files\MPICH dir was chosen as the install dir during installation.
Execute the following command to set the PATH environment variable appropiately.
set PATH=%PATH%;C:\Program Files\MPICH\mpd\bin;
If all the instructions were followed (assuming C:\Program Files\MPICH dir was chosen as the install dir), one should be able to invoke mpiRun from the command prompt.
Compilation and Execution
The above program has to be then compiled into an exe, say mpich-pi-a.exe. One can use MS Visual Studio for this. Now the program is ready for execution on MPICH. Following command can be used for executing on a single processor.
mpiRun -np <# procs that can be used> <path to exe>\<name of the exe> <seed> <iterations> <# of procs that should be used>
Example:
mpiRun -np 2 C:\mpichexamples\mpich-pi-a.exe 10 1000 2
The above instruction exeecuted from the command prompt will make use of both the processors that are available and execute mpich-pi-a.exe on both of them with a seed of 10 and 1000 iterations (which will be divided evenly among the two processors).
NOTE: If being execeuted on mutiple processors it is suggested to put the exe in a shared file system or make the same exe available on all the processors in the same directory (i.e.; the same path).
Web Services Solution
This comprises of three parts to it.
- A Service that offers the computation of PI using Monte Carlo method.
- A Deployment Descriptor that makes it public by deploying the service on a web server (such as tomcat).
- This information will then be used by the client programs to access the service that need to compute PI using Monte Carlo method.
While these solutions are described, the necessary steps involved in deploying and accessing the service is also briefly enunciated.
Web Service (Server Side) MonteCarloPI.java :
The service that computes PI takes as input the following parameters:
- the seed to the random number generator and
- the number of attempts it has to make to hit the dartboard.
It returns the number of successful hits to the dartboard.
Compile this class and put the MonteCarloPI.class file in C:\jakarta-tomcat-3.3.2\webapps\soap\WEB-INF\classes directory.
Deployment Decriptor MonteCarloDeploymentDescriptor.xml :
This is an XML file that provides information about the Service by specifying the class name and the methods the service has for the clients to access. This information can be used by the client programs to best use the service. Executing the following command will deploy the Service on the server at the URL specified and is available for the clients to access.
“java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml”
Sample Client Program MonteCarloClient.java :
The client program accesses mutiple PI services and gets as a result the number of successful attempts in hitting the dartboard. The successful attempts are consolidated to computes the value of PI. Compile this class like any other Java class and execute.
Installation, Compilation, and Execution
Tomcat and SOAP Installation
This instruction manual presupposes the installation of JDK 1.4x and that JAVA_HOME environment variable has been set.
Tomcat:
- Download any version of Tomcat from the Apache Jakarta Project. I used version 3.3.2 for these tests.
- Unzip the downloaded file. I unzipped to C:\, which put everything in the C:\jakarta-tomcat-3.3.2 directory.
- Start Tomcat by running
C:
cd \jakarta-tomcat-3.3.2 \bin
startup
- Test that Tomcat is running by pointing your browser to http://localhost:8080/index.html. You should get a page saying "If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!."
Apache SOAP Server:
- Download a version of Apache SOAP from the Apache XML pages. I downloaded the version 2.3.1 binary for these tests. You must use 2.2 or later to follow these instructions.
- Unzip the downloaded file. I unzipped to C:\, which put everything in the C:\soap-2_2 directory.
- Install Apache SOAP as a Tomcat Web application by running
C:
cd \jakarta-tomcat-3.3.2 \bin
shutdown
cd \jakarta-tomcat-3.3.2 \webapps
mkdir soap
cd soap
jar -xvf C:\soap-2_3_1\webapps\soap.war
cd \jakarta-tomcat-3.3.2 \bin
startup
- Test that Apache SOAP is installed by pointing your browser to http://localhost:8080/soap/index.html. You should get a page saying "Hello! Welcome to Apache-SOAP."
- Further test that Apache SOAP is installed by pointing your browser to http://localhost:8080/soap/servlet/rpcrouter. You should get a page saying "Sorry, I don't speak via HTTP GET- you have to use HTTP POST to talk to me."
Apache SOAP Client
- For the Apache SOAP client to work, Xerces, Apache SOAP, JavaMail and the Java Activation Framework should be in the CLASSPATH. It so happens that Tomcat includes usable versions of Xerces, JavaMail and Java Activation Framework. I set my CLASSPATH to the following.
C:\jakarta-tomcat-3.3.2\lib\common\ xerces.jar;
C:\soap-2_3_1\lib\soap.jar;C:\soap-2_3_1;
C:\jakarta-tomcat-3.3.2\lib\common\ mail.jar;
C:\jakarta-tomcat-3.3.2\lib\common\activation.jar
- Run one of the address book sample tests to check if the installation steps have been successful. Each example has a testit.bat script. So executing that script and watching for the results will suffice.
This finishes the installation and setup of the necessary software to run Web Services solution for Monte Carlo. We shall now take a look at the Web Services solution for computing PI using Monte Carlo method.
Compilation and Execution
- Compile both the client the server programs using the javac command.
- Place the server.class program at this location - C:\jakarta-tomcat-3.3.2\webapps\soap\WEB-INF\classes
- Deploy the server program using the following instruction
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml
- Execute the client program using the following instruction
java <client program> <seed> <iterations> <soap url1> ... <soap urln>
Example: java MonteCarloClient 10 10000 http://agent1.cs.siu.edu:8080/soap/servlet/rpcrouter http://agent2.cs.siu.edu:8080/soap/servlet/rpcrouter
PI example with Karajan
The implementations explained in the previous sections implement Monte Carlo PI program using various technologies. In this section we show how a Karajan workflow can make use of one of these implementations and deploy the program to a remote host, compile it, execute it and display the results to the user. For this to happen user should possess the knowledge of remote resources and have the permissons to use them.
There are two versions of the karajan workflow:
Sequential Karajan Workflow
The sequential version uses the sequential-pii.c program for deployment and execution purposes.
Parallel Karajan Workflow
The parallel version uses sequential-pii.c program that resturns the number of successful hits, consolidates and computes pi. It also makes use of hosts.xml file which defines the list of remote hosts. hosts.xml in turn uses security-cntxt.xml which sets the security context for the hosts in hosts.xml.
NOTE:
- Checkout all these files(*.c, *.xml) from the SVN and put it in .../cog-4_1_3.../dist/cog-4_1_3/examples/karajan folder.
- Note that the parallel version of the pi program will be executed on all the hosts in the hosts.xml file.
- hosts.xml file contains a list of remote hosts ( You do not have to install the cogkit on all these remote hosts. )that the user has access to. Since the programs make use of ssh provider, user should be able to ssh to these remote hosts.
- security-cntxt.xml file should have the corresponding authentication for each remote hosts.
- currentTimeMillis-def.xml file will be available in the .../cog-4_1_3.../dist/cog-4_1_3/examples/karajan folder.
Installation, Compilation, and Execution
After the CogKit has been |installed run the
.../cog-4_1_3.../dist/cog-4_1_3/bin/cog-workflow-gui
script from the command prompt. This will open the user interface for a workflow execution. Select either the karajan-sequential-pi.xml or the karajan-parallel-pi.xml and click on Start to being the execution. State changes will be displayed in the command prompt.
