CS475 Fall 2010 - HW 3

Memory-efficient Knapsack Dynamic Programming and parallelization

Problem Statement

Design and implement a recursive, memory efcient program to solve the knapsack problem for a knapsack of capacity C choosing out of N objects. The program should be memory efficient in the sense that only O(C) memory is saved. In this assignment you will implement a sequential program and two parallel versions of your sequential program. Most of your work may be done on the CS department machines, but your final program should compile and produce correct results on carver. You report for this assignment should be short and briefly explain the parallelizations performed

Divide and Conquer

In this program, you are going to use the divide-and-conquer approach to compute the entire solution in a memory efficient manner. Since you never build the entire table there will be no backtracking, as such, the base case will simply return the solution for a single element knapsack. The main recursive function that you write will have three parameters, start, stop and capacity. The base case (termination of the recursion) should be when you are solving a knapsack sub problem with a single item (start=stop). In the general case, you will divide the problem into two roughly equal halves some mid between stop and start. Then you will produce the last row of the table for the two halves, saving only the previous row of the table. You will use these two answer rows to determine how much capacity should be given to each of the two recursive calls.

Implement the part that computes the last row of each half in a row-by-row manner. Thus at any time, there are two arrays, curr and prev and the two are swapped at the end of each iteration of the outer loop.

Start off with the sequential (rowwise) code provided here, which is a slight modification of the code which was used in the knapsack lab. Your final code should take the same command line arguments and follow the same output format.

Parallel

Use the previous divide and Conquer program you wrote and parallelize the function that computes the last row. This would be a straight forward parallelization. Report the performance obtained as a function of no of threads and input problem size k2000

Task parallelism

Use the serial divide and Conquer program you wrote and parallelize using task parallelism feature of OpenMP. This is similar to the Merge sort task parallelism explored in the lab. Each subproblem is divided into two rougly equal halves untill the terminaing condition previouly specified, so this can easily be parallelized using the task feature.Again report the performance obtained as a function of no of threads and input problem size k2000

What/When:

How to Submit:

How to tar files:

Good luck and have fun!