Using any thread API, i need to implement a program that calculate multiplication of
two matrices
The input is a file with following structure :
Line 1: dim of the first matrix(m l)
Lines 2 to m+1:rows of the first matrix
Line m +2 :emty
Line m +3 :dim of the second matrix(l n)
Lines m +4 to m+4+n:rows of the second matrix
The following is a sample input file :
3 4
1 2 3
1 2 3
1 2 3
4 2
5 6
5 6
5 6
5 6
i need using C++ and i worked under windows
??????????????need any help plz plz
[Update1]
#include <cstdlib>
#include <math.h>
#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;
DWORD i,j,k;
int dim;
struct param {
int x;
int y;
};
int MAT1[10][10];
int MAT22[10][10];
int MAT3[10][10];
int r1,c1,r2,c2;
DWORD WINAPI product(LPVOID S){
param *p1=(param *)S;
for(i=0;i<r1;i=i+2)
{
for(j=0;j<c2;j++)
{
for(k=0;k<c1;k++)
{
MAT3[i][j]+=MAT1[i][k]*MAT22[k][j];
}
}
}
return 0;
};
int main(int argc, char *argv[])
{
HANDLE ThreadHandle;
param *p1=new param;
DWORD ThreadId;
p1->x=i;
p1->y=j;
printf("enter dim of mat1:\n");
scanf("%d%d",&r1,&c1);
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("enter mat1[%d][%d]:",i,j);
scanf("%d",&MAT1[i][j]);
}
}
printf("\n");
printf("enter dim of mat2:\n");
scanf("%d%d",&r2,&c2);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("enter mat2[%d][%d]:",i,j);
scanf("%d",&MAT22[i][j]);
}
}
if (c1=r2)
{
for(i=0;i<r1;i+2)
{
for(j=0;j<c2;j+2)
{
MAT3[i][j]=0;
}
}
ThreadHandle = CreateThread(
NULL, 0, product, &p1, 0, &ThreadId);
for(i=0;i<r1;i=i+2)
{
for(j=0;j<c2;j++)
{
for(k=0;k<c1;k++)
{
MAT3[i][j]+=MAT1[i][k]*MAT22[k][j];
}}}return 0;
if(ThreadHandle != NULL)
{
WaitForSingleObject(ThreadHandle, INFINITE);
CloseHandle(ThreadHandle);
}
}
printf("\n matrix1 \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d \t",MAT1[i][j]);
}
printf("\n");
}
printf("\n matrix2 \n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d \t",MAT22[i][j]);
}
printf("\n");
}
printf("\n multiplication of mat...\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("%d \t",MAT3[i][j]);
}
printf("\n");
}
}
[/Update1]
[Update2]
i tried to use file but i failed so i let user enter input on Dos screen but after enter dim of matrix1 and then enter MAT1...enter Dim of matrix 2 then enter matrix 2 after that there is no response and didn't multiply the two matrix i think there is some thing error but i dn't know where ??...i used Dev compiler C++ !!!!
[/Update2]