Exploiting parallelism within Mandelbrot computation

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;
};
}\$
end

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
d=(2.0/(float)(N-1))
in order to have the virtual processors on the boarders to compute the function on the edges of the complex square. In particular:
• pixel defines the function computed by each virtual processor. It is basically the same C function discussed in the problem description (See 1) plus an initialisation phase in which the virtual processors (j,k) computes the initial values for zi and zr. The P3L keywords \${ and }\$ encapsulate the part in which plain C code can be used. The definition
pixel in (int resolution, int j, int k) out (int colour)
...
end
is equivalent to a C functional definition in which the result is explicitly stated in the out parameter list.
• mandelbrot is an instance of the map construct which defines N x N virtual processors. Each virtual processor (i,j) computes pixel on the complex point it is in charge of and outputs the corresponding colour.

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