--- /dev/null
+<!--#set var="root_directory" value="../../.." --><!--#include virtual="$root_directory/shared/header.shtml"-->
+
+<h1>Assignment #3</h1>
+<p><em>Due Friday, October 16, 2009</p>
+
+<h2>Purpose</h2>
+
+<p>Learn to time C codes — specifically sorting algorithms.</p>
+
+<p>Note: Please identify all your work.</p>
+
+<h2>Background</h2>
+
+<p>The basic idea of timing a code is to make two time calls — one
+before and one after the code you want timed, and then take the
+difference. There are many ways to make such time calls in C. We will
+use <code>gettimeofday()</code> because it allows timing to
+µ-seconds. The <code>gettimeofday</code> call is described by</p>
+
+<pre>
+#include <time.h>
+int gettimeofday(struct timeval *tv, struct timezone *tz);
+</pre>
+
+<p>The return value is 0 for success and -1 for an error. The function
+places the time and timezone information into memory specified
+by <code>*tv</code> and <code>*tz</code> respectively. We don’t care
+about the timezone, so we can place a <code>NULL</code> pointer
+there.</p>
+
+<p>In order to understand how to get at the time we need to understand
+the <code>timeval</code> struct. This is defined by</p>
+
+<pre>
+struct timeval{
+ time_t tv_sec;
+ suseconds_t tv_usec;
+};
+</pre>
+
+<p>The type <code>time_t</code> is essentially an integer type used to
+store the number of seconds elapsed from the beginning of the Unix
+epoch (12:00 UTC on 1 January 1970). The <code>suseconds_t</code> type
+is similar: it is an integer that holds the the number of µ-seconds
+that have elapsed 1 since the last second. So, if we want the current
+time to the µ-second since the Unix epoch we have</p>
+
+<pre>
+struct timeval t1;
+gettimeofday(&t1,NULL);
+printf("Unix rulz ur world for %d.%06d seconds!\n", t1.tv_sec, t1.tv_usec);
+</pre>
+
+<p>Note the formatting for the µ-seconds.</p>
+
+<h2>Assignment</h2>
+
+<h3>Part A</h3>
+
+<p>Write a C code (or modify the one in the web pages) that wraps a
+sorting algorithm in order to time it using
+the <code>gettimeofday</code> call. Print out the total time
+elapsed. Repeat this for a sequence of lists of exponentially growing
+size, say $2^n$ with $1 \le n \le N \sim 20$ (hint: make one long
+unsorted list of length $2^N$, say with a random number generator, and
+just take subsets of this list). Do this for both a bubble and a
+quicksort. Make a log-log plot of the times to compare the algorithms.
+What is the order of the algorithms (i.e., visually compare against
+curves of the form $c_1 n^2$ and $c_2 n \ln n$)? Do you want to
+bubble sort large lists (i.e. what value of $N$ did you give up
+at)?</p>
+
+<h3>Part B</h3>
+
+<p>Write a parallel version of the bubble sort code. Use an algorithm
+that leaves the task of ordering the sub-lists to processes 1
+to <code>size-1</code> (<code>size<code> being the number of
+processes), using process 0 to merge back the ordered sub-lists into
+an ordered large one and performing a check (sum of members) on the
+sort.</p>
+
+<h3>Part C</h3>
+
+<p>Insert timing tools in the parallel code. Time separately: the
+sorting of the sublists, the merging of the sublists and the total
+times for both sort and merge (total sorting times). Plot the total
+sorting times for the serial code <em>and</em> the parallel code for
+the values of $N$ used in Part A. Find out the $N$ dependence of the
+merge times.</p>
+
+<!--#include virtual="$root_directory/shared/footer.shtml"-->