Project 4 -- IPC

Part 1

Due Monday, December 3, 6:00 pm

(Note that the due date is later than originally listed in the class schedule. I do not intend to move the due date off any more, as this is getting close to final exams as it is. This means that if you have conflicts with other courses, such as term assignments for those courses, you should get an early start on Project 4 and have it done early, rather than hoping to get an extension.)

NOTE: If you are even a minute late, submitting this project, you lose 20%. If you are worried about potentially being late, turn in your homework ahead of time. Do this by submitting them electronically then giving the hard copy to me or the TA during office hours or by sliding it under my office door within twenty-four hours after the time it is due. Do not send assignments to me through email or leave them in my departmental mail box.

One recent trend in solving problems that require a great deal of computational effort is to break them up into smaller pieces and let volunteers work on each piece. Probably the best-known example of this is the SETI@home project. This project allows people around the world to help Search for ExtraTerrestrial Intelligence (SETI) by downloading and analyzing radio telescope data on their home (or work or school) computers, when those computers would otherwise be more or less idle.

In this project, users download client software that will, in turn, download data and search through it looking for interesting patterns. When done with one collection of data, the client software reports back and asks for another. The server, naturally, provides the data collections and processes the reports. (For details, see: <http://setiathome.ssl.berkeley.edu/>.)

Other "@home" projects, such as Genome@home (that allows your computer to design genomes) have been started in immitation of SETI@home.

For this assignment, you will create both client and server software for two less dramatic but nonetheless instructive distributed computing projects, which I will call Prime@school and Prime@home. In these projects, each client will request a number to try to factor and will report back to the server when it has finished checking that number to see whether it is prime. The server will do a little verification on the factors found as well as give the clients numbers to check.



The Prime@school Assignment

For this assignment, you will create two programs. The client will be called primeatschool and the server will be called primeatschoold.

primeatschool

The primeatschool program will work as follows:

A user will invoke primeatschool with the command line:

    % primeatschool <server address> <return address>
    
where <server address> is replaced by the "address" of the server from which the client will get its numbers and <return address> is the return "address" to which the server should send these numbers.

When it is invoked, the primeatschool program will contact the server, request a number, and give the return address to which the server should send the number.

(For more on "addresses", see IPC below.)

The primeatschool program will wait up to 30 seconds for a reply from the server. If a reply does not come within 30 seconds, primeatschool will print the message "Server not responding." and exit. Otherwise, primeatschool will process the message it receives from the server.

If the message from the server is a positive number, this is the number that the client (primeatschool) should factor. The client should factor this number and send back to the server a message that includes one of the factors found for this number. If no factors are found (the number is prime), the client should send the number 0 in its message. The client should then request another number to factor.

If the message from the server is any other value, primeatschool should print an error message and exit.

To shut down primeatschool, you should send it the SIGUSR1 signal. When the client receives this signal, it should stop sending requests to the server, remove its FIFO entry in the file system, complete factoring the number on which it is working, send this last factorization to the server, and print a message saying that it has shut down successfully.

primeatschoold

The primeatschoold server will work as follows:

When started, primeatschoold will read a file called primeatschoolfile containing the following information in the following format:

Before running primeatschoold for the first time, you should create the file primeatschoolfile with 1 as the number on the first line and a blank line for the other.

After reading the file, primeatschoold will enter a loop where it alternately reads messages from clients and sends replies to them. The replies will be as follows:

If there are any values on the "missed numbers" list in memory, primeatschoold should send the first of these values to the client and remove this number from the list in memory.

Otherwise, primeatschoold will send the client the value of the highest number sent out previously plus 2 and record this value as the first line and in the "missed numbers" list in the file.

If the client sends in a number and a purported factor, primeatschoold will verify that the factor really is a factor of that number and, if it is, will remove it from the "missed numbers" list in the file.

If the client sends in a number and a zero (which indicates that a prime has been found), the server will remove that number from the "missed numbers" list in the file, add it to the end of a file called schoollikelyprimes, and spawn off a child process that will verify whether the number is prime. If the child finds that the number is prime, it will record it in a file called schoolprimes. Whether or not the number proves to be prime, the child process will remove that number from the schoollikelyprimes file after checking it. Both schoollikelyprimes and schoolprimes will have one number per line in the file.

To shut down the server, you should send it the SIGUSR1 signal. When the server receives this signal, it should stop reading requests from clients, remove its FIFO entry in the file system, stop sending messages to clients, and wait for all of its children to exit. When its last child has exited, it should print a message saying that it has shut down successfully.

IPC

For IPC, both the client and the server in the Prime@school portion of the assignment will use FIFOs. Unfortunately, this will severly limit the usefulness of these programs because the server and all of its clients will have to use the same computer, which means that while we are distributing the processing over processes, we aren't distributing it over processors (unless we have a multi-processor machine). This shortcoming will be rectified with the second portion of this assignment, Prime@home. However, until we talk about IPC that can cross machine boundaries (next week in class), we can still see how the client-server architecture works.

The "address" of the server (name of the FIFO to send requests to the server) will be of the form "~<username>/primeserv" where <username> is replaced by the actual username of the user who starts up the server. So, for example, if I ran your copy of the server code, the "address" would be "~hougen/primeserv". (Note that this means that you shouldn't hard-code this address into your program, it should get it by looking at the UID of the process, then looking up that UID in the passwd file to find the corresponding username.)

The "address" of the client will be any valid FIFO name that the user of the client software specifies on the command line when starting primeatschool.

On start-up, both the server and the client will attempt to create their FIFO file system entries, if they do not already exist, and will make them world-writable. (You should also make directories in which these FIFOs reside accessible by world, so that anyone on the same computer can start up a client and connect it to your server and get numbers back.)

There will be two message types that the client may send to the server.

There will be message type that the server may send to the client. This will be formatted as follows:

    <number>,
where <number> is the number to be factored.



What to turn in.

NOTHING YET! You will also do the second part of the assignment, Prime@home, before turing in anything and will turn in both parts of the assignment together.

When you do turn in your assignment, you will turn in both a hard copy and an electronic copy of your assignment. You will be given instructions on how to send electronic copies. Do not send them to me though email.

Both the hard copy and the electronic copy will contain a write-up and all source code for primeatschool, primeatschoold, primeathome, and primeathomed. The electronic copy will also contain the executables of primeatschool, primeatschoold, primeathome, and primeathomed. The electronic copy of your write-up should not be in a proprietary format (such as MS Word); it should be either in plain ASCII text or in a portable format (such as Postscript or PDF). Your source code should either be in a single file for each program, called primeatschool.c, primeatschoold.c, primeathome.c, and primeathomed.c, respectively, or in several files that can be compiled and linked using make. In the latter case, primeatschool.c, primeatschoold.c, primeathome.c, and primeathomed.c (or primeatschool.cxx, primeatschoold.cxx, primeathome.cxx, and primeathomed.cxx) will contain the function main() and you will include your makefile and it will be named makefile. The executables generated by your makefile should be called primeatschool, primeatschoold, primeathome, and primeathomed.

Your source code should be well structured and well commented. It should conform to good coding standards (e.g., no memory leaks).

Your write-up will contain 1/2 to 1 page (roughly 80 characters per line, 50 lines per page) explaining the data structures and algorithms used in your code. This page limitation does not include figures used in your explanation, which are encouraged and may take up any amount of space. (This explanation does not remove the requirement that your code be well commented.)



Other

You may write your program from scratch or may start from programs for which the source code is freely available on the web or through other sources (such as friends or student organizations). If you do not start from scratch, you must give a complete and accurate accounting of where all of your code came from and indicate which parts are original, which are changed, and which you got from which other source. Failure to give credit where credit is due is academic fraud and will be dealt with accordingly.

As noted in the syllabus, you are required to work on this programming assignment in a group of at least two people. It is your responsibility to find other group members and work with them. The group should turn in only one (1) hard copy and one (1) electronic copy of the assignment. Both the electronic and hard copies should contain the names and student ID numbers of all group members. If your group composition changes during the course of working on this assignment (for example, a group of five splits into a group of two and a separate group of three), this must be clearly indicated in your write-up, including the names and student ID numbers of everyone involved.