1 / 13

Computer Science 320

Computer Science 320. Parallel Image Generation. The Mandelbrot Set. The Mandelbrot Set. A set of points defined as follows: given a point (x, y), compute a sequence of other points (a i , b i ), i = 0, 1, 2, … a 0 = 0 b 0 = 0 a i +1 = a i 2 – b i 2 + x b i +1 = 2 * a i * b i + y

dolph
Download Presentation

Computer Science 320

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. Computer Science 320 Parallel Image Generation

  2. The Mandelbrot Set

  3. The Mandelbrot Set A set of points defined as follows: given a point (x, y), compute a sequence of other points (ai, bi), i = 0, 1, 2, … a0 = 0 b0 = 0 ai+1 = ai2 – bi2 + x bi+1 = 2 * ai * bi + y If each point in (ai, bi) stays finite, (x, y) is in; otherwise, not in

  4. The Mandelbrot Set If each point in (ai, bi) stays finite, (x, y) is in; otherwise, not in Can’t do an infinite # of points, so if (ai, bi) ever exceeds a distance of 2 from the origin, it’s not in or: if (ai2 + bi2 )1/2 > 2 for some i

  5. The Mandelbrot Set or: if (ai2 + bi2 )1/2 > 2 for some i If we do 1,000 points, if i reaches this limit before the distance exceeds 2, we’ll call the point in, even if further tests might show it to be out

  6. Program Resources • Will use the Parallel Java Graphics (PJG) format, which is lossless and larger, but uses faster compression, than PNG format • Will generate color values for each point and save these in a PJG file

  7. Program Inputs • Image width and height • Coordinates of the image center point • Image resolution in pixels per unit • Maximum number of iterations to test for membership • Exponent in formula to calculate pixel hues • Output file name

  8. Pixel Matrix, Image File, Hue Table // Create image matrix to store results. matrix = new int [height] [width]; image = new PJGColorImage (height, width, matrix); // Create table of hues for different iteration counts. huetable= new int [maxiter+1]; for (inti = 0; i < maxiter; ++ i){ huetable[i] = HSB.pack(/*hue*/ (float) Math.pow(((double)i) / ((double)maxiter), gamma), /*sat*/ 1.0f, /*bri*/ 1.0f); } huetable[maxiter] = HSB.pack (1.0f, 1.0f, 0.0f);

  9. Optimizing Matrix Access // Compute all rows and columns. for (int r = 0; r < height; ++ r){ int[] matrix_r = matrix[r]; double y = ycenter + (yoffset - r) / resolution; for (int c = 0; c < width; ++ c){ double x = xcenter + (xoffset + c) / resolution; Allows access to a cell with a single index operation

  10. Iterate Until Convergence // Iterate until convergence. int i = 0; double aold = 0.0; double bold = 0.0; double a = 0.0; double b = 0.0; double zmagsqr = 0.0; while (i < maxiter && zmagsqr <= 4.0){ ++ i; a = aold * aold – bold * bold + x; b = 2.0 * aold * bold + y; zmagsqr = a * a + b*b; aold = a; bold = b; } // Record number of iterations for pixel. matrix_r[c] = huetable[i];

  11. Parallelize the Program • Each pixel value can be computed independently, so divide the matrix rows among the threads • All inputs are shared • No per-thread or local variables need synchronization • No padding needed

  12. The Parallel for Loop // Compute all rows and columns. new ParallelTeam().execute(new ParallelRegion(){ public void run() throws Exception{ execute (0, height-1, new IntegerForLoop(){ public void run (int first, int last){ for (int r = first; r <= last; ++ r){ int[] matrix_r = matrix[r]; double y = ycenter + (yoffset - r) / resolution;

  13. Behavior of Parallel Program

More Related