Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 160 – Lecture 10 Programs 1 and 2. Program 1 Write a “launcher” program to specify exactly where programs are to be spawned, gather output, clean.

Similar presentations


Presentation on theme: "CSE 160 – Lecture 10 Programs 1 and 2. Program 1 Write a “launcher” program to specify exactly where programs are to be spawned, gather output, clean."— Presentation transcript:

1 CSE 160 – Lecture 10 Programs 1 and 2

2 Program 1 Write a “launcher” program to specify exactly where programs are to be spawned, gather output, clean up on error … Write a ring gather program Write a tree gather program

3 Code Outline for Program 1 Code outlines were given in lecture 5 We will go over an example implementation for all three parts –Looking carefully at each PVM function –Using XPVM to control a virtual machine Space-time diagrams Trace masks Replaying traces This will interactive

4 Program 2 Implement the Sobel (Section 11.5 in W+A) edge detection algorithm –Input/output files in PGM format –Master/worker configuration –“Bag of tasks” load balancing –Data decomposed by strips Assignment available on the web on Friday

5 Edge Detection Basic problem: Try to find edges (areas of local sharp contrast) in a greyscale image –Think back to basic 1D calculus When |df/dx| is high, function is changing rapidly –For 2D problems this is generalized to gradients.  f(x,y) = (  f/  x,  f/  y) The goal is to find areas in a picture where the |  f(x,y) | is high.

6 Approximating the Magnitude of the Gradient |  f(x,y)| =  (  f/  x) 2 + (  f/  y) 2 – For computational simplicity, this is approximated as |  f/  x| + |  f/  y| Let’s consider the following 3 x 3 matrix of values x0x0 x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8

7 Calculating the |Gradient| at X 4 X 4 is the pixel of interest. Could try an approximation as –  f/  x = x 5 – x 3 (difference left and right) –  f/  y = x 7 – x 1 (difference top and bottom) One gets much better approximation of all surrounding pixels are used to approximate the gradient

8 The Sobel Operator Look at calculating  f/  y –  f/  y = x 6 –x 0 + 2(x 7 – x 1 ) + x 9 – x 3 –This is only a weighted average of the gradient by using neighboring pixels. Extra weight is given to the pixels directly above and below the center pixel of interest  f/  x = x 2 –x 0 + 2(x 5 – x 3 ) + x 8 – x 6

9 Cross Correlation Mask Pixels Cross correlation is  i  j x i w j Want to calculate the cross-correlation at each point in an image using two masks. x0x0 x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 w0w0 w1w1 w2w2 w3w3 w4w4 w5w5 w6w6 w7w7 w8w8 

10 Final Calculation Calculate a new x 4 ’ with the following Sobel formula –x 4 ’ = (1/9) * ( |x 6 –x 0 + 2(x 7 – x 1 ) + x 9 – x 3 | + |x 2 –x 0 + 2(x 5 – x 3 ) + x 8 – x 6 ) ) Need to do this at every point in the picture.

11 Master/Worker Model Master reads input/writes final output Give an input file, divide the image into K horizontal strips K Strips

12 Master Spawns P Workers Master will start P (  K) workers The first P strips are sent to the P slaves. –Slaves compute the Sobel transform on their strip. Return transformed image to the master As the master gets data returned, it doles out more strips until the entire image is converted.

13 Bag of tasks Load Balancing For this problem, a task is the Sobel transform of an image strip. –Workers may compute at different speeds Faster workers get more work to do (Sounds like life ) Slower workers get less work to do For few workers and may tasks, most workers are busy all of the time.

14 What to do at the edge of regions to transform? Strip j needs 1 row of pixels from strip j+1 and strip j-1 Have master send these 1 pixel rows as part of the jth strip. at edges, consider the image to have pixel value 0 outside the pixel area. j j-1 j+1

15 Master Pseudo-code Read command line arguments Spawn P worker tasks Read complete image into an array, pad edges with zeros (N+2)x(M+2) Nrows=ceil((N+2)/K) // rows per block Pkidx=0; //row index to pack stripsLeft = K; for (i = 0; i < P; i++){ label strip i pack label of strip i pack the dimensions of strip i pack the data of strip i send ith strip to ith worker; }

16 Master Pseudo Code continued stripsleft = K – P; Stripsxformed = 0; While (stripsleft) receive transformed strip from any worker; stripsxformed ++; determine which strip has been sent; Save data; pack strip S = [K – stripsleft]; send strip S to this worker; stripsleft--; }

17 Master Continued While (stripsxformed < K) receive transformed strip from any worker; stripsxformed++; determine strip that was sent; save data; stripsxformed++; } Broadcast a done message to every worker; Write out transformed data;

18 Worker Pseudo code done = 0; While (!done) { receive message from parent; (pvm_parent()) determine message tag; (pvm_bufinfo()) if (Tag == donemessage) break; unpack strip id; unpack strip dimension; unpack strip data; transform data; pack strip id, dimension; pack transformed data; send back to parent; }


Download ppt "CSE 160 – Lecture 10 Programs 1 and 2. Program 1 Write a “launcher” program to specify exactly where programs are to be spawned, gather output, clean."

Similar presentations


Ads by Google