Homework 4
Due Tuesday, December 2

Implement the Hyperquicksort from our printed lecture notes, using NXLib on the ACS SPARCs. The documentation for NXLib is on my NXLibWeb page.

There will be three command-line arguments:

   argv[1]     k, the number of nodes 
   argv[2]     length of the array to be sorted
   argv[3]     debug/test mode (1 means yes, 0 means no)

Each PE will generate its own initial chunk, to serve as 1/k of the initial array, as random numbers between 0 and 1023.

In debug/test mode, printf() will be used to display the initial numbers, in a "baton-passing" fashion similar to that used in Phil Nico's "hot potato" program: PE 0 will print its chunk, then send a message to PE 1 to print its chunk, after which PE 1 will send such a message to PE 2, etc.; after PE k-1 does its printing, it will send a message to PE 0. In debug/test mode, after the sort is complete, again use the "baton-passing" method to print out the results.

Use qsort() to do the local sorting in the Hyperquicksort algorithm. You can see an example of its usage on my Unix/C Web page.

Measure run time using the Unix "time" command. Run on array lengths 10,000, 100,000 and 1,000,000, with the number of nodes being 2, 4 and 8. This means a total of 9 runs. Report your results, plus some remarks on the effects of increasing the number of nodes for different array sizes, in a README file.

Make sure that you use the NXLib in a manner which does not cause problems for other ACS users. Henry Naftulin will generate some random numbers to assign sets of ACS SPARCs for each homework group. Please MAKE SURE TO WORK ONLY ON MACHINES IN YOUR ASSIGNED SET. Also, make sure that you check for "zombie" nxdaemon processes on all machines in your set before you log out. Be sure to do your debugging on small arrays with small numbers of processors. And try your best to finish BEFORE the due date; if many people are working on this problem on the due date, machine response will be extremely slow, and your timings will be quite inaccurate.

Use the following method to generate the random numbers on the i-th node, say into an array x :

   int seed;

   /* make sure each node gets a different sequence */
   seed = i*i + 1;
   srand(seed);

   /* generate the numbers (/
   for (i = 0; i < 10; i++) 
      x[i] = rand() % 1023;

Package your .c files, your makefile and your README file into a .tar.gz.uu file as usual for submission for grading.

BE CAREFUL! Make sure your code accounts for all possible cases, such as those in which ALL elements of a node are less than its subcube root's median. Otherwise your program will hang, and you will falsely believe you have a bug in the parallel processing software rather than in your own code.