From: W. Trevor King Date: Tue, 14 Sep 2010 15:21:15 +0000 (-0400) Subject: Convert sorting assigment.pdf to XHTML. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3f3c8a290fe4a5a75b45e14861e76231e26c570c;p=parallel_computing.git Convert sorting assigment.pdf to XHTML. --- diff --git a/assignments/archive/sorting/assigment.pdf b/assignments/archive/sorting/assigment.pdf deleted file mode 100644 index fdfa040..0000000 Binary files a/assignments/archive/sorting/assigment.pdf and /dev/null differ diff --git a/assignments/archive/sorting/index.shtml.itex2MML b/assignments/archive/sorting/index.shtml.itex2MML new file mode 100644 index 0000000..51e93a1 --- /dev/null +++ b/assignments/archive/sorting/index.shtml.itex2MML @@ -0,0 +1,91 @@ + + +

Assignment #3

+

Due Friday, October 16, 2009

+ +

Purpose

+ +

Learn to time C codes — specifically sorting algorithms.

+ +

Note: Please identify all your work.

+ +

Background

+ +

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 gettimeofday() because it allows timing to +µ-seconds. The gettimeofday call is described by

+ +
+#include 
+int gettimeofday(struct timeval *tv, struct timezone *tz);
+
+ +

The return value is 0 for success and -1 for an error. The function +places the time and timezone information into memory specified +by *tv and *tz respectively. We don’t care +about the timezone, so we can place a NULL pointer +there.

+ +

In order to understand how to get at the time we need to understand +the timeval struct. This is defined by

+ +
+struct timeval{
+  time_t         tv_sec;
+  suseconds_t    tv_usec;
+};
+
+ +

The type time_t 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 suseconds_t 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

+ +
+struct timeval t1;
+gettimeofday(&t1,NULL);
+printf("Unix rulz ur world for %d.%06d seconds!\n", t1.tv_sec, t1.tv_usec);
+
+ +

Note the formatting for the µ-seconds.

+ +

Assignment

+ +

Part A

+ +

Write a C code (or modify the one in the web pages) that wraps a +sorting algorithm in order to time it using +the gettimeofday 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)?

+ +

Part B

+ +

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 size-1 (size 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.

+ +

Part C

+ +

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 and the parallel code for +the values of $N$ used in Part A. Find out the $N$ dependence of the +merge times.

+ + diff --git a/assignments/index.shtml b/assignments/index.shtml index 3cca6ed..de2ab91 100644 --- a/assignments/index.shtml +++ b/assignments/index.shtml @@ -5,7 +5,7 @@