Programming assignments #3 and #4


The goals of these two assignments are two-fold.  First, to give you a better understanding
of shared memory and threads.  Second, the performance tradeoff between the two OS
features.

The program I have written is mergesort.

Program #3 (40 points): modify shared.c so that 8 processes are spawned instead of 2.  Each process
should be assigned a portion (1/8th) of the array.  Each process will sort that portion.  On return,
a process needs to merge the two results.  An additional 10 bonus points
will be awarded for those who create exactly 8 processes and assign a portion of the work to
the parent process (in my example, the parent does no sorting, just merging).

Program #4 (100 points):  Modify your solution in program #3 to use threads instead of shared memory.  You will have to redeclare the array "in" to have local storage.  An example thread call is provided
as thread.c. Note: You will need to compile your code as "gcc file.c -lpthread".

Analysis (60 points):  You are to create two graphs, one for the shared memory and one for the thread program. Your graph's x coordinate will be labeled "Workload Size".  The y coordinate will be "Time (seconds)". For each graph, you will plot 3 lines.  Amount of time taken for user time, amount of time taken for system, and total time (the summation of user and system time).  Your plots *MUST* be computer
generated.  You may use any plotting tool.  gnuplot is available as well as MS Excell.

You will create 12 workloads.  Your workloads will be random integers (not including 0).  Your
workloads will be sized   2,4,8,16,32,64,128,256,512,1024,2048,4096.

To collect the data, you should use the UNIX facility called "time".  An example of
its usage:


  time a.out < input-file
 

Submission Procedure:  Submissions of this project will be in paper format AND email).  You
should turn in a copy of Program #3, Program #4, and your two plots.  Your submission should
be computer generated (no hand writing).  Your name must be on all parts of your submission. You must email me your programs as well so that I may test them

NOTE: You MUST use recursion to spawn the processes/threads. If you do not use recursion, you will enjoy a 30% reduction in points for each programming part.