Midterm1-2009

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

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

View Full Document Right Arrow Icon
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]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online