1 / 18

CSE 160 – Lecture 10

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 up on error … Write a ring gather program Write a tree gather program. Code Outline for Program 1. Code outlines were given in lecture 5

Download Presentation

CSE 160 – Lecture 10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

  7. Calculating the |Gradient| at X4 • X4 is the pixel of interest. Could try an approximation as •  f/x = x5 – x3 (difference left and right) •  f/y = x7 – x1 (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 = x6 –x0 + 2(x7 – x1) + x9 – x3 • 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 = x2 –x0 + 2(x5 – x3) + x8 – x6

  9. Cross Correlation • Mask Pixels  Cross correlation is ij xiwj Want to calculate the cross-correlation at each point in an image using two masks.

  10. Final Calculation • Calculate a new x4’ with the following Sobel formula • x4’ = (1/9) * (|x6 –x0 + 2(x7 – x1) + x9 – x3| + |x2 –x0 + 2(x5 – x3) + x8 – x6)) • 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? j-1 • 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

  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; }

More Related