Due: week 6.
Divide a simple task between threads. The task can easily be divided in sub-tasks requiring no cooperation at all. See the caching effects, and the costs of creating threads and of switching between threads.
Write several programs to compute the product of two matrices.
Have a function that computes a single element of the resulting matrix.
Have a second function whose each call will constitute the thread function (and will be called on several threads in parallel). This function will call the above one several times consecutively to compute several elements of the resulting matrix. Consider the following ways of splitting the work between threads (for the examples, consider the final matrix being 9x9 and the work split between 4 threads):
For debugging, each time you call the function computing an element of the resulting matrix, print the row and column of the element being computed and the thread number (0 to nr_threads-1) of the current thread.
Experiment with various values for (and document the attempts and their performance):