CS267 Assignment 3: Parallelize Knapsack

Due Saturday 19 March 2011 at 11:59pm

Overview

The purpose of this assignment is introduction to programming in Partitioned Global Address Space (PGAS) languages.

You need to parallelize a solution of the 0-1 knapsack problem. You have N items with positive integer weights w[1], ..., w[N] and values v[1], ..., v[N]. The goal is to find a subset of the items such that its total weight does not exceed given bag capacity C and its total value is the largest possible.

We consider solving the problem using dynamic programming. Define T[i,j] to be the maximum value that can be attained with weight ≤ i using items 1, ..., j. Then it satisfies the following recurrence relation:

T[i,j] = max( T[i,j-1], T[i-w[j],j-1]+v[j] ).

The value of the optimal solution is found at T[C,N]. Backtracking over the choices gives the items used in the solution.

Source Code

The serial and parallel implementations that are set up to compile on the target platforms are given below. We will run this assignment on Franklin. Note that there is a Cray UPC compiler on Franklin and Hopper, but the naive code yields incorrect semantics when compiled with the Cray compiler.

serial.cpp
a serial implementation that you need to efficiently parallelize,
parallel.upc
a naive and very inefficient parallel implementation in UPC,
Makefile
a Makefile for Franklin/Hopper (with notes on which modules to load),
job-serial, job-parallel,
sample batch files to launch jobs on Franklin,
knapsack.tar
all above files in one tarball.
The supplied parallel code uses cyclic layout and computes entries corresponding to the same item (T[:,j]) in parallel. Barrier synchronization is used when proceding to next item. This code implies a lot of fine-grain communication and runs slower than the serial code.

You need is to get a reasonably good scaling versus the serial code on a sufficiently large problem. Consider using block row or block column layout, bulk communication and pipelined computation. Using UPC is a requirement.

You may work in groups of 2 or 3. Email the GSIs your write-up and source codes.

Resources


[ Back to CS267 Resource Page ]