Posted by: Nas October 20, 2006
Login in to Rate this Post:
0
?
Slackdemic bro, do you know about P threads? I have been working on the following program. Could you shed some lights on ?
Given two matrices A and B, where A is a matrix with M rows and K columns and
matrix B contains K rows and N columns, the matrix product of A and B is
matrix C, where C contains M rows and N columns. The entry in matrix C for
row i column j (C_i,j) is the sum of the products of the elements for row i in
matrix A and column j in matrix B. That is:
__K___
C_i,j = / A_i,n X B_n,j
/_______
n = 1
For example, if A were a 3-by-2 matrix and B were a 2-by-3 matrix, element
C_3,1 would be the sum of A_3,1 and B_2,1.
For this project, calculate each element C_i,j in a separate worker thread.
This will involve createing M X N worker threads. The main - or parent -
thread will initialize the matrices A and B and allocate sufficient memory
for matrix C, which will hold the product of matrices A and B. These matrices
will be declared as global data so that each worker thread has access to A, B
and C. Matrices A and B can be initialized statically, as shown below:
#define M 3
#define K 2
#define N 3
int A [M][K] = { {1,4}, {2,5}, {3, 6} };
int B [K][N] = { {8,7,6}, {5,4,3} };
int C [M][N];
--------------------------------------------------------------------------------------------------
Following is the code, that I have to modify. Instead of defining the matrix size as 5, Matrices A and B should be initialized statically as given above. If you have time could you please look into it ? I modified the following code but somehow answer is not coming right.
In UNIX, to compile the following program mat.c
cc mat.c -o mat -p.thread
./mat 1
#include
#include
#include
#define SIZE 5 /* Size of matrices */
int N; /* number of threads */
int A[SIZE][SIZE], B[SIZE][SIZE], C[SIZE][SIZE];
void fill_matrix(int m[SIZE][SIZE])
{
int i, j, n = 0;
for (i=0; i