This preview shows pages 1–2. Sign up to view the full content.
CS 140 Assignment 4:
Cilkified Inner Products
Assigned February 3, 2010
Due by 11:59 pm Wednesday, February 10
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.
This note was uploaded on 12/27/2011 for the course CMPSC 140 taught by Professor Gilbert during the Fall '11 term at UCSB.
 Fall '11
 GILBERT

Click to edit the document details