Kamran Hameed
2008-05-16 17:43:48 UTC
folks.. i have a simple C program that calculates the product of two
4*4 matrices. Here is the Code.
#include<stdio.h>
#include<string.h>
void printA(int array[4][4]) {
int i,j;
for( i=0;i<4;i++) {
for(j=0;j<4;j++) {
printf("%*d",6,array[i][j]);
}
printf("\n");
}
}
void mult(int arr1[4][4],int arr2[4][4],int result[4][4]) {
int i,j,k,s;
for(i=0;i<4;i++) {
for( j=0;j<4;j++) {
s=0;
for(k=0;k<4;k++) {
s+=arr1[i][k] * arr2[k][j];
}
result[i][j]=s;
}
}
}
main() {
printf("Serail Matrix Multiplication Program\n");
int arr1[4][4]={{1,2,3,4},{5,6,7,8},{1,2,3,4},{5,6,7,8}}; /*Creating a
4*4
Matrix of Integers*/
/*Creating another 4*4 Matrix of Integers*/
int arr2[4][4]={{11,21,31,41},{1,1,1,1},{1,2,3,4},{5,6,7,8}};
int result[4][4]={0};
printf("Array 1 is ........\n");
printA(arr1);
printf("Array 2 is ........\n");
printA(arr2);
printf("After Multiplication, Result is ........\n");
mult(arr1,arr2,result);
printA(result);
}
Now i want to parallelize it i-e i want the product to be calculated
by different processes but i am a bit lost how to do it?
Any Guide Lines?
4*4 matrices. Here is the Code.
#include<stdio.h>
#include<string.h>
void printA(int array[4][4]) {
int i,j;
for( i=0;i<4;i++) {
for(j=0;j<4;j++) {
printf("%*d",6,array[i][j]);
}
printf("\n");
}
}
void mult(int arr1[4][4],int arr2[4][4],int result[4][4]) {
int i,j,k,s;
for(i=0;i<4;i++) {
for( j=0;j<4;j++) {
s=0;
for(k=0;k<4;k++) {
s+=arr1[i][k] * arr2[k][j];
}
result[i][j]=s;
}
}
}
main() {
printf("Serail Matrix Multiplication Program\n");
int arr1[4][4]={{1,2,3,4},{5,6,7,8},{1,2,3,4},{5,6,7,8}}; /*Creating a
4*4
Matrix of Integers*/
/*Creating another 4*4 Matrix of Integers*/
int arr2[4][4]={{11,21,31,41},{1,1,1,1},{1,2,3,4},{5,6,7,8}};
int result[4][4]={0};
printf("Array 1 is ........\n");
printA(arr1);
printf("Array 2 is ........\n");
printA(arr2);
printf("After Multiplication, Result is ........\n");
mult(arr1,arr2,result);
printA(result);
}
Now i want to parallelize it i-e i want the product to be calculated
by different processes but i am a bit lost how to do it?
Any Guide Lines?