Exploiting parallelism within Mandelbrot computation

next up previous
Next: Compiling with the Up: Computing the Mandelbrot set Previous: The problem

Exploiting parallelism within Mandelbrot computation

  We can easily exploit MAP parallelism in the computation of the Mandelbrot set on a square of the complex plane by distributing each complex point to a distinct virtual processor, computing the colour of each point in parallel and then collecting all the colours in a two-dimensional array colour[][]. This is easily expressed by the following P3L fragment:

pixel in (int resolution, int j, int k) out (int colour)
       int i;
       zr = -1.0 + (float)(j)*d;
       zi = -1.0 + (float)(k)*d;
       cr = zr;
       ci = zi;
       zrs = 0;
       zis = 0;
       for (i=0; i<resolution; i++)
         if (!(zrs+ zis > 4.0))
                 zrs =zr *zr;
                 zis =zi *zi;
                 zi =2.0*zr*zi+ci;
                 zr =zrs-zis+cr;
                 colour =i;

map mandelbrot in(int index_i[N], int index_j[N], int resolution) 
               out(int colour[N][N])
    pixel in(resolution, index_i[*i], index_j[*j]) out(colour[*i][*j])  
end map
this fragment computes Mandelbrot of a square of NxN complex points with vertices (-1.0,-1.0), (-1.0,1.0), (1.0,-1.0), and (1.0,1.0). Each point is computed by a distinct virtual processor indexed with (i,j) (i=0...N-1,j=0...N-1). The sampling within the square is done with distance
in order to have the virtual processors on the boarders to compute the function on the edges of the complex square. In particular:

The P3l group ( susanna@di.unipi.it )
Fri Sep 8 17:29:42 METDST 1995