CS 3733 Operating Systems, Spring 2008 Assignment 6


Due Monday, April 28

In this assignment you will convert your Assignment 5 programs to work with multiple machines. Instead of making multiple threads you will farm out parts of the problem to multiple servers on the network.

Use the port numbers you were given in the recitation.

Put all of the code for this assignment in a fresh directory. For each part, perform the following tests from Assignment 4: tests 9, 10, 17, 18, 19.

Part 0
Start with the serverp parallel server from Chapter 18 of USP. Copy it info factor_server.c and modify the makefile to compile it also. The program will still take a single command line parameter which is a port number it will listen on.

When a connection comes in, the child process will receive three numbers from the client. These will be interpreted as:

  1. a number to factor, n
  2. the smallest factor to test for, low
  3. the largest factor to test for, high
When it gets these numbers it will test each number in the range from low to high (inclusive) to see if it is a factor of n. If it is, it will send the value back to the client.

Some of the factors found may not be prime, but since we are only interested in prime factors, we can divide n by the factor and use the reduced value. Do not change the range. However, once the value you are testing gets past sqrt(n) you can stop looking. When done, send the reduced value back to the client and close the connection.

If the server child receives an error writing to the client, it (the child) should terminate. We will see how this will be used later in the assignment.

We need to decide on a format for sending the numbers over the network. Since we do not want to worry about byte order for 8-byte values, we will send the values as ASCII digits, high digit first. We will terminate all numbers with a blank character.

This method allows us to test the server using the client2 program from Chapter 18. You can send the values to the server just by typing them on the command line of client2. Since client2 is bidirectional, it will also display the result gotten back from the server.

Test the server using several of the tests from Assignment 3.

Part 1
Write a program that will use the server you wrote in Part 0. The program will takes 3 or more command line parameters. The first is the number to factor, n. The second is a port number for connecting to the servers. The remaining command line parameters are the names of hosts running your server from Part 0.

The idea: Count the number of hosts, divide the range 2 to sqrt(n) into that number of approximately equal parts. Connect to each server, giving it the value of n and the appropriate range. Then wait for values to come back from each server, storing them with saveValue as before, until the server closes the connection, indicating it has no more numbers to find.

Implementation: After you connect to a server, send the server the appropriate values and create a thread to handle the receipt of values from the server. This will allow the other servers can be handled in parallel. Also, the thread will not need to be passed anything but the file descriptor it is monitoring.

When all threads have completed, you should have a list of all possible factors. Remove the ones that are not prime, as before. Then duplicate the values that are multiple factors and print the results as before.

Part 2
This is optional for extra credit, but not too hard.
Assume that all numbers used are 8-byte values and send them through the network in network byte order. You will need to write a function called htonll which converts an 8-byte value to network byte order. One way to do this is to test your machine to see if it uses the same byte order as the network. (You can do this by comparing htons(1) with 1) and only switching the order if it is not.

Test your programs by running some servers on the Solaris machines with the client running under Linux.

Part 3
This is optional for extra credit.
If the thread that is handling the smallest range, gets a value, we can probably speed up the other servers by using a smaller value of n. If the first thread finds a value, cancel the other calculations (by closing the connection file descriptors) and killing the threads. Start new connections to the servers and new threads that use the smaller value of n.

Part 4
This is optional for extra credit.
In Part 3 we killed the threads and closed the network connections when we wanted to stop the calculations on the server. This will only stop the calculation when the server tries to write a value back to the client and gets and error. If there are no factors to find in this range, the server will keep calculating and will be less efficient when you connect to it again with the smaller value of n.

Find and implement a method that will allow a client to stop the server's calculation immediately. Here are 2 ideas:

Find a case in which your solution to Part 4 is much faster than you solution to Part 2. Include timing tests that show your results. Write a paragraph describing how you implemented this.

Handing in your assignment
On each output page, indicate which machines the client and server were run on. You only need to turn in the output from the client, but indicate which and how many servers were used.

Use this cover sheet.