This preview shows pages 1–2. Sign up to view the full content.
CS 240A Assignment 4:
Cilkified Inner Products
Assigned April 26, 2010
Due by 11:59 pm Monday, May 3
The purpose of this assignment is to gain familiarity with Cilk++ constructs and tools, as
well as to think about different ways of parallelizing an algorithm using Cilk++. You will
write a parallel routine that computes the inner product (dot product) of two arrays in
three different ways. For grading purposes, both correctness and performance will count.
1.
Background
The inner product of two vectors is the sum of their elementwise multiplications. In pure
C, the inner product of two integer arrays, each of size
n
, can be implemented as follows:
int innerprod = 0;
for(int i=0; i< n; ++i)
{
innerprod += a[i] * b[i];
}
In C++, the standard library has a dedicated function for computing the inner product. It
is made available by including the <numeric> header. For the purposes of this assignment
(and this class), you don’t have to know and use C++, but you’re allowed to do so
because the Cilk++ compiler is an extension of C++ and will accept all C++ constructs.
int innerprod = std::inner_product(a, a+n, b, 0);
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '09
 GILBERT

Click to edit the document details