#include <pthread.h>
#include<stdio.h>
int i,j;
int A[3][2]={{6,5},{4,3},{2,1}};
int B[2][3]={{1,2,3},{4,5,6}};
int C[3][3];
struct para{
int row;
int col;
};
void* multiply (void *parameters){
int i,j,r,c;
struct para *abc;
abc=(struct para*)parameters;
r=abc->row;
c=abc->col;
int sum=0;
for(i=0;i<2;i++)
sum=sum+(A[r][i]*B[i][c]);
C[r][c]=sum;
}
int main(){
printf("PRINTING MATRIX A\n");
for(i=0;i<3;i++){
for(j=0;j<2;j++)
printf("%d ",A[i][j]);
printf("\n");
}
printf("PRINTING MATRIX B\n");
for(i=0;i<2;i++){
for(j=0;j<3;j++)
printf("%d ",B[i][j]);
printf("\n");
}
int i,j;
struct para *RC=malloc(1);
pthread_t threadID;
pthread_attr_t
attributes;
pthread_attr_init
(&attributes);
for(i=0;i<3;i++){
RC->row=i;
for(j=0;j<3;j++){
RC->col=j;
pthread_create(&threadID, &attributes, multiply,RC);
pthread_join(threadID,NULL);
}
}
printf("PRINTING
RESULTING MATRIX\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++)
printf("%d ",C[i][j]);
printf("\n");
}
}
No comments
Post a Comment