Laboratory Exercises For Computer Science 213

Laboratory on Parallel Algorithms and Memory Management

Laboratory on Parallel Algorithms and Memory Management

Goals: This laboratory exercise provides practice with parallel algorithms and with memory management algorithms.


Parallel Algorithms

Prefix Sums

Consider the discussion of the parallel computation of prefix sums as described in class by Mr. Stone; an outline of that material may be found at http://www.cs.grinnell.edu/~stone/courses/operating-systems/parallel-algorithms.xhtml

  1. Consider a vector of 16 elements,

    
    2  7  1  8  2  8  1  4  1  5  9  2  6  5  3  5
    
    Now suppose this is used as the input vector for procedure accumulate-vector. Show the values stored in the vector at each step of the computation, following the model computation illustrated in Mr. Stone's notes.

Rank and Truncated Rank

Consider the class discussion and handout concerning the rank and the truncated rank of an item in a vector.

  1. Consider the arrays A = (2, 3, 4, 5, 7, 9, 10, 13, 14, 16, 17) and B = (3, 6, 9). For each element in B, compute both rank(bi, A) and trank(bi, A).

Parallel Merging

Consider the class discussion and handout concerning the parallel merging of two arrays.

  1. Consider the arrays A[1],...A[n] and B[1],...B[2n], suppose all values in A and B are ordered and distinct, suppose rank(A[i], B) = 2i-1 for each i = 1, ..., n, and suppose rank(B[j], A) = j / 2 (integer division) for j = 1, ..., 2n. When arrays A and B are merged to yield an array C[1], ..., C[3n], show the relative positions of the elements of A[i] and B[j] in C. (In other words, what sequence of A's and B's yield C: A[1], B[1], A[2], ... or B[1], A[1], B[2], ... or B[1], B[2], A[1], ... or something else?) Briefly justify your answer.


Memory Management

Suppose a computer memory contains 64 units of space. Consider the following sequence of memory requests.


Allocate:   A 10
Allocate:   B 8
Allocate:   C 15
Allocate:   D 12
Deallocate: A
Allocate:   E 11
Deallocate: C
Allocate:   F 8
Allocate:   G 8
Deallocate: D
Suppose that this sequence of requests was handled by each of the following allocation algorithms. Show the resulting configuration of memory, together with all appropriate pointers and flags. Assume that adjacent blocks of free memory are NOT coalesced.

  1. First-fit
  2. Next-fit (circular free list kept with pointer to last free block)
  3. Best-fit (free list kept in ascending order of block size)
  4. Worst-fit (free list kept in descending order of block size)
  5. Binary-buddies (optional for extra credit)

Suppose the first-fit algorithm were combined with the boundary tag buddy approach to allow for more efficient coalescing of free space.

  1. Show the resulting memory configuration, together with all appropriate pointers and flags.


Each memory allocation has special advantages and disadvantages.

  1. (Optional for extra credit) Can you find a sequence of allocations and deallocations that can be satisfied by the boundary-tag buddy algorithm, but which cannot be met by the binary-buddy algorithm, due to difficulties of internal fragmentation?

  2. (Optional for extra credit) Can you find a sequence of allocations and deallocations that can be satisfied by the binary-buddy algorithm, but which cannot be met by the boundary-tag buddy algorithm, due to difficulties of external fragmentation?

This document is available on the World Wide Web as

     http://www.math.grin.edu/~walker/courses/213.fa98/lab-memory.html

created November 10, 1998
last revised November 5, 2000