Matrix multiplication using fork


Can just someone tell some tips how to make that happen, because in my code i need to input n -> number of process but i dont understand when i need to make 3 processes using fork this impossible, because fork makes 1-> 2 pr. and multiplication needs to be like that for each row the children need to multiply it and just the parent needs to print out the result.
here is my matrix multiplication... and if my code have some issues let me know :D

#include <iostream>
#include <ctime>
using namespace std;

int main()
{
srand(time(NULL));
int l, m;
do{
cout<<"Input: ";
cin>>l>>m;
}while(l<0 || m < 0);
int** matrixA = new int*[l]; //matrix A[l][m]
for(int i = 0; i < l; ++i)
matrixA[i] = new int[m];
int** matrixB = new int*[m]; //matrix B[m][l]
for(int i = 0; i < m; ++i)
matrixB[i] = new int[l];
int** matrixC = new int*[l]; //matrix C[l][l]
for(int i = 0; i < l; ++i)
matrixC[i] = new int[l];
for(int k=0; k<l; k++)
{
for(int j=0; j<m; j++)
{
matrixA[k][j] = rand()%9+1;
cout<<matrixA[k][j]<<" ";
}//for
cout<<endl;
}//for
for(int k=0; k<m; k++)
{
for(int j=0; j<l; j++)
{
matrixB[k][j] = rand()%9+1;
cout<<matrixB[k][j]<<" ";
}
cout<<endl;
}

for(int i=0; i<l; i++)
{
for(int j=0; j<l; j++)
{
matrixC[i][j]=0;
for(int k=0; k<m; k++)
{
matrixC[i][j]= matrixC[i][j]+ matrixA[i][k] *matrixB[k][j];
}
cout<<matrixC[i][j]<<" ";
}
cout<<endl;
}
system("pause");
return 3;
}
Topic archived. No new replies allowed.