In this document we show how to create a distributed application to compute the number PI using the ProActive Grid Middleware. Distributed programming is achieved using the ProActive deployment framework combined with the active object model.
Download and install the JDK 5.0 Update 9 from here.
Set the environment variable JAVA_HOME to the java installation location.
Go into the tutorial directory: ProActive/src/org/objectweb/proactive/examples/pi/. This directory contains:
config/ <-- Configuration directory
descriptors/ <-- Deployment descriptors directory
doc/ <-- Documentation directory
fractal/ <-- Component directory
scripts/ <-- Launch scripts directory
Interval.java <-- The parameter passed to remote objects
PiBPP.java <-- The main code
PiComputer.java <-- The remote object code (worker)
Results.java <-- The results returned by the workers
MyPi.java <-- Base class to test Pi with ProActive
In this step by step we will implement our own version of PiBPP.java.
Create the file MyPi.java inside the tutorial directory with initially the following content:
package org.objectweb.proactive.examples.pi; import org.objectweb.proactive.ProActive; import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; import org.objectweb.proactive.core.descriptor.data.VirtualNode; import org.objectweb.proactive.core.group.ProActiveGroup; import org.objectweb.proactive.core.node.Node; class MyPi{ // global variables will go here public static void main(String args[]) throws Exception{ Integer numberOfDecimals = new Integer(args[0]); String descriptorPath = args[1]; // the main code will go here }
Inside the main we add the code for acquiring the resources.
ProActiveDescriptor descriptor = ProActive.getProactiveDescriptor(descriptorPath); //Parse the xml descriptor descriptor.activateMappings(); //Acquire the resources VirtualNode virtualNode = descriptor.getVirtualNode("computers-vn"); //Get the virtual node named "computers-vn" Node[] nodes = virtualNode.getNodes();
PiComputer piComputer = (PiComputer) ProActiveGroup.newGroupInParallel( PiComputer.class.getName(), new Object[] { numberOfDecimals }, nodes); int numberOfWorkers = ProActiveGroup.getGroup(piComputer).size();
Interval intervals = PiUtil.dividePI(numberOfWorkers, numberOfDecimals.intValue());
ProActiveGroup.setScatterGroup(intervals);
Result results = piComputer.compute(intervals);
Result result= PiUtil.conquerPI(results);
System.out.println("Pi:"+result);
package org.objectweb.proactive.examples.pi; import org.objectweb.proactive.ProActive; import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; import org.objectweb.proactive.core.descriptor.data.VirtualNode; import org.objectweb.proactive.core.group.ProActiveGroup; import org.objectweb.proactive.core.node.Node; public class MyPi { public static void main(String args[]) throws Exception{ Integer numberOfDecimals = new Integer(args[0]); String descriptorPath = args[1]; ProActiveDescriptor descriptor = ProActive.getProactiveDescriptor(descriptorPath); descriptor.activateMappings(); VirtualNode virtualNode = descriptor.getVirtualNode("computers-vn"); Node[] nodes = virtualNode.getNodes(); PiComputer piComputer = (PiComputer) ProActiveGroup.newGroupInParallel( PiComputer.class.getName(), new Object[] { numberOfDecimals }, nodes); int numberOfWorkers = ProActiveGroup.getGroup(piComputer).size(); Interval intervals = PiUtil.dividePI(numberOfWorkers, numberOfDecimals.intValue()); ProActiveGroup.setScatterGroup(intervals); Result results = piComputer.compute(intervals); Result result= PiUtil.conquerPI(results); System.out.println("Pi:"+result); descriptor.killall(true); System.exit(0); } }
© 2001-2007 INRIA Sophia Antipolis All Rights Reserved