Program #2 -- CS 491 


Revied



Shared Memory

In the use of parallel computing environments, the use of multiple
processes and shared memory is an important environment.  Recall that 
processes contain independent address space -- this means that if you
want to use multiple processes to compute a result, you have to figure
out a way to make the results of each process known to the other processes.
This can be done by use of shared memory.

In this programming environment, you will be using "fork()" and shared
memory directives to enable the multiple processes to perform your computation.
This ONLY works on machines that are SMP or support a shared memory 
environment.


A) In mergesort, you are to fork off N  processes for performing the mergesort
on the left and right hand sides (one process for the left and one process for the
right).  The parent process needs to wait until both 
processes are completed before performing the merge of the processes.  The
basic process would be:

 1) read in the input
 2) call mergesort
     if L < U, then fork two processes, one will do the LHS, and one will do the
            RHS.
     on exit of the two children process, the parent does the merge.


IMPORTANT -- unless you use shared memory for handling the array, the results
of the LHS and RHS will not be known to the parent.  Click here for an example
of using shared memory between a parent process and a child process

 shared.c  



B) You are then to modify your mergesort to take one additional input item.  This
is to indicate the level of recursion you want to fork processes to.  After that level,
the child process will do all of the remainder recursion.


You are to run performance analysis on A versus B.  You are to use the UNIX
"time" command to collect time to run these processes.  You are to run this on input
of size 32, 64, 128, .... 1024.   You are to run this with level 4 for B versus
B.

You are to report the type of machine you ran this on , operating system, and number of processors.


Can you find an input size where B is significantly faster than A?