Midterm1-2009

# Midterm1-2009 - CS 140 Midterm 1 5 February 2009 Problem...

This preview shows pages 1–2. Sign up to view the full content.

CS 140 Midterm 1 -- 5 February 2009 Problem 1 [20 points total] Each of p processors starts out with the coordinates (x, y) of a single point in the plane. Our goal is to compute the center of gravity (cx, cy) of the p points, and the average distance avgdist from the center of gravity to the points. The values of cx , cy , and avgdist should end up on processor 0. Here are the formulas: cx = (x[0] + . .. + x[p-1]) / p cy = (y[0] + . .. + y[p-1]) / p dist[i] = sqrt( (x[i] - cx) 2 + (y[i] - cy) 2 ) avgdist = (dist[0] + . .. + dist[p-1]) / p For example, if p = 3 and the points are (0, 0), (1, 2), and (2, 1 ), then (cx, cy) is (1, 1), the distances are sqrt(2), 1, and 1, and avgdist comes out to be (2+sqrt(2))/3 or about 1.14. (1a) [10 points] Using pseudo-code, show how to do this in MPI using send and recv . You don’t have to write a complete syntactically correct program, just the computations and MPI calls. (1b) [10 points]

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.

### Page1 / 2

Midterm1-2009 - CS 140 Midterm 1 5 February 2009 Problem...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online