Requires access to a multi-core machine.
Learning Objectives:
Matrix Manipulation is a simple example of how to apply the ideas of parallelism to a numerical problem. When encountering large matrices that must produce a product between them the amount of computations that must occur tend to accelerate at a drastic rate. For example to multiply two 1000x1000 matrices (which produce a 1000x1000 matrix) 1 billion calculations produce the product matrix. Because these instructions are not interdependent (the calculations at one coordinate of the resulting matrix never effect any other point within it) we can divide up the work and use multiple threads or processes to get parts of the resulting matrix and put them together.
The POSIX thread (pthread) implementation of this problem is almost as simple as can be made of the pthread implementation. Race conditions and deadlocks are nearly non-existent, and shared data is minimal. This sets up a gentle pthread introduction. Since the data that is shared is the data originally passed (you cannot send multiple parameters with pthreads, all data passed must be encapsulated in a data structure in c), one may have to lock structure to make copies to local variables when the pthread begins to execute its method. The solution will require the main thread to wait for other threads to finish their work, meaning use of attributes and the function pthread_join will be used at a basic level. For executing critical sections of code the use of mutexes can be used, but since there are very few points at which mutual exclusion is required this is minimal.
To Compile matMulti.c that uses pthreads the command is:
gcc -Wall -o pMult matmulti.c
-lpthread
Students will create a single program, using pthreads, that randomly generate 2 NxN matrices filled with floating point values and then calculates the product of the matrices. When generating these random numbers, make use of drand48(), and seed the random generator with the value of 47u (see the man page for drand48 for further information). Fill in the matrix that will be the product with 0s. You will be required to implement a print function that would produce in the following way:
Given the 4x4 identity matrix, your printed output should look like:
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
Use the time utility that is built into Linux to track the execution times of pMult 4 X, pMult 8 X, and pMult 16 X on os-class for X = {10, 100, 500, 1000}. Include those times in a table in your write up.
Things to consider when writing up your results:
All source files that are required to make the binary, a makefile, and the writeup (do not include the executable). Upon reception calling make should generate the executable file for testing. Please make use of the tar utility to create an archive for submission.