Use pthreads to implement matrix multiplication (of 4x4 integer matrices). (This is the Project in Chapter 4 of Silberschatz, Galvin, and Gagne, pp. 149-151).
C[i][j] = A[i][0]*B[0][j] + A[i][1]*B[1][j] + ... + A[i][m-1]*B[m-1][j]
const int dim = 4; int A[dim][dim]; int B[dim][dim]; int C[dim][dim];In all relevant loops, you should use the constant dim instead of 4. This makes it easy to change your program to multiply dim-by-dim for different values of dim.
void matrix_input(int mat[][dim], char* name)
void matrix_print(int mat[][dim])to print each matrix in a rectangular form. Your program should output several lines explaining the computation, in a form similar to
The matrix product of A and B is C.
pthread_t tid[dim][dim];
g++ myprogram.cpp -lpthreadand to include the line
#include<pthread.h>in the introductory section of your program.
loftin@pegasus.rutgers.eduby midnight on the due date, Monday, March 5.
Input the 16 entries of the 4 x 4 matrix A: 1 2 3 4 0 -1 -2 -3 7 8 -1 1 5 10 -7 3 Input the 16 entries of the 4 x 4 matrix B: 9 1 0 0 5 7 -5 -7 0 0 2 2 8 1 4 5 The matrix product of 1 2 3 4 0 -1 -2 -3 7 8 -1 1 5 10 -7 3 and 9 1 0 0 5 7 -5 -7 0 0 2 2 8 1 4 5 is 51 19 12 12 -29 -10 -11 -12 111 64 -38 -53 119 78 -52 -69
~loftin/public_html/op/project/solution