Homework 4 Due Wednesday, June 8. In this assignment you will write a sorting program on the CAE hypercube. It is REQUIRED that you use an enumeration sort. This works simply by counting, as the following example shows. Consider the array x = (12,5,59,62,1). (I.e. x[0] = 12, x[1] = 5, and so on.) Let y denote an array which will be the sorted version of x. We will construct y as follows. We ask, for example, How many of x's elements are less than 12? The answer is two (the elements being 5 and 1). Therefore y[2] should be 12. Continuing in this way for the rest of the elements of x, i.e. 5, 59, etc., we find that y is (1,5,12,59,62). (Though I am using array notation here, you should make your arrays dynamic, not static.) This is illustrated in the program ~matloff/Pub/Hypercube/Enum.c on my CAE account. This program is not intended for the hypercube; it is simply there to show how an enumeration sort works. The program generates a random array of integers, and then uses an enumeration sort to produce the sorted version of the array. Note that, in order to allow arrays of any length, this program creates and accesses the arrays via pointers. It is REQUIRED that your hypercube program be implemented as follows. Node 0 generates a random array x, and sends copies of x to all the other nodes. Let c[i] denote the number of x[j] which are less than x[i] (j != i). Then y[c[i]] = x[i]. (BEFORE YOU READ ANY FURTHER, CHECK THIS ON A FEW CASES OF i FOR THE EXAMPLE ABOVE.) Each of the nodes, including node 0, will construct an equal piece of sorted array c, and send that piece back to node 0 (node 0, of course, need not send to itself). For example, if there are four nodes in all, and the array size is 20, then node 0 will determine c[0] through c[4], node 1 will determine c[5] through c[9], and so on. The other nodes will send their pieces of c to node 0; the latter, after receiving all the pieces, will report y to the screen. (For convenience, you may assume that the array length N is an integer multiple of the number of processors.) Information on compiling and running your program on the hypercube is contained in Phil's mini-manual. When you submit your work to the Reader, include not only your source file(s) but also a `script' record of a run on the hypercube; this run must be on the real hypercube, not the simulator. However, during your debugging you will probably prefer to use the hypercube simulator, bsim. Its command structure is similar to that of the real hypercube. However, you compile your program differently for it. If your source file is, say, hwk4.c, you would compile it by gcc hwk4.c /usr/local/ipsc/lib/bsimlib.a You would then run this program on the simulator, as follows, say for a 4-node hypercube: %bsim iPS2 sim> getcube -t4 iPS2 sim> load a.out iPS2 sim> start iPS2 sim> quit % (By the way, the simulator works by setting up a separate Unix process for each simulator node. Take a look at this via the Unix ps command.) Unfortunately, as far as I can tell, bsim's load command does not allow you to specify the argv arguments, so you may wish to read your program's argument (N, the array length) from a file. When you are ready to run your program on the real hypercube, you will use icc to compile it, as the mini-manul mentions. Note that icc is in the directory /usr/local/ipsc/ssd/i860/bin.sun4. It is HIGHLY, HIGHLY RECOMMENDED that you get an early start on this program. It does not look like it will be feasible to extend the due date.