Indice

TBB Lab exercises

Lab time 06/05/2016

Practical info

wget https://www.threadingbuildingblocks.org/sites/default/files/software_releases/linux/tbb44_20160413oss_lin.tgz

Simple "farm" with mandelbrot

Compute the Mandelbrot set like in the MPI lab farm exercise. Program parameters define a square n*n (or rectangular n*m) subset of the complex plane, the number of samples i,j for each coordinate, the max number of iterations per point MaxI.

The first exaple will not really be a farm: generate the input stream of points with a parallel for (either two nested or a single one with a 2D range). You will need to create appropriate range(s) for that.

The computation for each point is actually given by the mandelbrot function, which returns the number of iteration until the point diverges, or MaxI if the limit is exceeded.

Choose a plane region near the border of the mandelbrot set so that you get both some of the points of the set and some outside in your computation.

Can you dynamically optimize the grain according to the input parameters?

Things to do
Useful places around the Mandelbrot set
X,Y = square center R = square size
X = -0.7463 Y = 0.1102 R = 0.005

Actual farm with Mandelbrot

Restructure the program to work with a stream of points (or stream of sets of points) that are generated and enter a parallel_do; we still compute the Mandelbrot set function, but the sequential function is modified such that it can take in input (and produce as output) a partial computation on a point of the plane.

You can compute on points in the stream and recycle them if the computation takes too long. Use the parallel_do methods to reinsert in the loop those points that are not completed, and let those that are completed flow out of the do_loop.

Extensions

If you consider the computation can have a specific grain size (size of the sets of points that are provided to each parallel_do inner function) the approach lends itself to become a sort of divide and conquer, where the long computation of some points are considered “big tasks” that are fed back in input after some time. These tasks can be repacked to allow completed points in the same task to not uselessly flow back into the loop. Proper design of the task structure minimizes data copying in this phase too.