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 mapthis 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 in (int resolution, int j, int k) out (int colour) ... endis equivalent to a C functional definition in which the result is explicitly stated in the out parameter list.