Assignment 2: A Basic Compute Farm
Purpose
Specification
Each large Internet computing project, such as SETI@HOME, tackles some problem that has a simple parallel decomposition. We will call such "embarrassingly parallel" problems piecework-parallel, indicating that a problem in this class has a piecework decomposition: The problem decomposes into objects that implement Task, and whose execute methods return values that can be composed into a solution to the original problem.
Fig. 1: Pieceworktask decomposition topology
In this assignment, you build a basic compute farm infrastrure for hosting piecework-parallel problems. The client decomposes the problem, constructing a set of Task objects. These tasks are passed to a Space, which makes them available to compute servers, called Computer objects, which function much like those in your first assignment. The results computed by Computers are returned to the Space. The client retrieves results from the Space, composing them into a solution to the original problem.
The API
Result interface
Result objects are minimally mutable.
package api;
public interface Result<T> extends java.io.Serializable
{
T getValue();
void setValue( T value );
long getRunTime(); // of the Task, as seen by the Computer that executes it
}
Task interface
package api;
public interface Task<T> extends java.io.Serializable
{
Result<T> execute();
}
The Computer interface
package system;
public interface Computer extends java.rmi.Remote
{
Result execute( Task task ) throws java.rmi.RemoteException;
}
The Client-to-Space interface
package api;
public interface Client2Space extends java.rmi.Remote
{
public static String SERVICE_NAME = "CLIENT_2_SPACE";
void put( Task task ) throws java.rmi.RemoteException;
Result take() throws java.rmi.RemoteException;
}
The client decomposes the problem into a set of Task objects, and passes them to the Space via the put method. In principle, these task objects can be processed in parallel by Computers. After passing all the task objects to the Space, the client retrieves the associated Result objects via the take method. This method blocks until a Result is available to return the the client. Thus, if the client sent 10 Task objects to the Space, it could execute:
Result[] results = new Result[10];
for ( int i = 0; i < results.length; i++ )
{
results[i] = takeResult(); // waits for a result to become available.
}
If a particular Result needs to be associated a particular Task (e.g., a Mandelbrot Result), this information is passed via the Result object. Based on this association, if it matters, it composes the result values into a solution to the original problem.
The Space
- Implements the remote Client2Space interface described above.
- Implements a remote interface, called Computer2Space, that contains the following method:
- Tolerates faulty Computers
package system;
import api.*;
public interface Computer2Space extends java.rmi.Remote
{
public static String SERVICE_NAME = "COMPTER_2_SPACE";
void register( Computer computer ) throws java.rmi.RemoteException;
}
Faulty Computers
For the purposes of this assignment, a computer is defined to be faulty when a Remote method invoked on it returns a RemoteException. The Space accommodates faulty computers: If a computer that is running a task returns a RemoteException, the task is assigned to another computer.
The Space implementation's main method instantiates a Space object and binds it into its rmiregistry.
The space's implementation of register should instantiate a ComputerProxy, which is a separate thread. This thread's run method loops forever, taking available tasks, invoking its associated Computer's execute method with the task, and putting the returned Result object in a data structure for retrieval by the client. The Java LinkedBlockingQueue may be useful.
The Computer Implementation
- Computer's main method gets the domain name of its Space's machine from the command line. Using this, it gets a remote reference to the Computer2Space service from the rmiregistry.
- It registers an instance of itself with the Space.

Fig. 2: The client-Space-computer architecture.
Task classes
For each of the Task classes that you defined in the 1st assignment, define a corresponding Task class that solves part of the original problem. The decompositions need not be masterpieces of efficiency. For the Traveling Salesman Problem, partition the set of all possible tours into p parts. For example, if there are n cities, you can partition the set of tours into n - 1 parts: those that begin with cities
- 1, 2
- 1, 3
- ...
- 1, n
The clients
Define a client that:
- gets the domain name of a Space's machine from the command line;
- gets a remote reference to the Client2Space service from the rmiregistry.
- for each application (Mandelbrot and TSP), it:
- instantiates a large problem instance;
- Mandelbrot problem instance parameter values:
- -2.0, -2.0
- 4.0
- 1024
- 512
- EuclideanTsp problem instance: use the following list
of
12 cities as a problem instance:
Each line that follows has the x
and y
coordinates of a city, starting
with city 0 and ending with city 11:
1 1
8 1
8 8
1 8
2 2
7 2
7 7
2 7
3 3
6 3
6 6
3 6
If you plot these cities, then (I think) a minimal tour is: 0, 4, 8, 9, 5, 1, 2, 6, 10, 11, 7, 3. (Since I have arrived at this solution by inspection, this may not be optimal.) The cost of this tour is 20 + 8sqrt(2).
- suitably display the arguments.
- decomposes the problem instance into tasks, sending each to the Space via the put method;
- retrieves the results from the Space via take, and composes them into a solution to the original problem, which is displayed suitably.
Deployment
- Start a Space
- Start c Computers.
- Start your client
- Record the elapsed time for each of the client's problems.
- Record the average Task execution time for each problem.
- client, executes the tasks itself
- client, Space, and computer are all instantiated in the same JVM
- client, Space, and computer are instantiated on different JVMs running on the same machine
- client, Space, and computer run on different machines.
Analysis
- Offer an explanation for the differences in job execution times.
- To improve your understanding of what is going on, what other measurements would you like to see included?
- Include comments about improving the infrastructure architecture.
Paper Summary
Submit a 1-page summary, entirely in your own words, of the paper titled, "How to Build a ComputeFarm."
Deliverable
Mail <cappello@cs.ucsb.edu> a jar file, named <name>.jar, where <name> is the CS computer account username of 1 member of the pair. It should include the following directories and files:
Directories
- documents - has an index.html file that contains links to:
- readme.html: provides any explanation needed to build your system, and and run each component.
- javadoc, a directory that contains the javadoc of your
- api interfaces
- Task classes: constructor parameters and execute method return values.
- experimental results: a spreadsheet.
- your analysis, in either html or pdf.
- your paper summary, in either html or pdf.
- source - a directory containing the following subdirectories, reflecting the package structure:
- api, which contains Task, Result, and Client2Space.
- client, which contains your client class[es]
- system, which contains your Computer, Computer2Spaces, ComputerImpl, and Space classes.
- tasks, which contains your Task and Result classes (each Task/Result class pair may be in a subpackage, if you prefer)
- test - your Java unit test source files. Each test class is in the same package as the class it tests.
- library - has executables, typically jar files, that are not written by your team, but are needed to run your project.
- policy - has policy file[s].
Files
- build.xml file with targets to:
- build: builds your system: Creates a computer.jar, space.jar, and client.jar, and tasks-dl.jar.
- runSpace: starts a Space.
- runComputer: starts a Computer .
- runClient: starts a client .

