As you can see through my code , I am calling class Calculation through the function multithread_calculation()(which is in another class) in order to implement a multithreading calculation of two matrices. The problem is, that i need the function calculate_product to return the array with the result. Or the other possible solution is to pass it by reference. None of these tactics are working so I am kind of lost. Thanks .
PS : I tried to use the ParametirizedThread instead of ThreadStart but guess i don't know how to use it correct.
class Calculation
{
int[,] arrayA;
int[,] arrayB;
int rows, cols,k;
public Calculation(int [,]arrayA,int [,]arrayB,int rows,int cols,int k)
{
this.arrayA = arrayA;
this.arrayB = arrayB;
this.rows = rows;
this.cols = cols;
this.k = k;
}
public void calculate_product()
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
for (int l = 0; l < k; l++)
arrayC[i, j] += arrayA[i, l] * arrayB[l, j];
}
}
}//end of function
private void multithread_calculation()
{
int[,] arrayC = new int[matrix1_rows, matrix2_cols];
//create an array of threads
Thread[] t;
//create object to be calculated
Calculation[] calc;
calc = new Calculation[10];
t = new Thread[10];
Stopwatch stop = new Stopwatch();
stop.Start();
for (int i = 0; i < 10; i++)
{
//create an object
calc[i] = new Calculation(arrayA, arrayB, matrix1_rows, matrix2_cols, k);
ThreadStart ts = new ThreadStart(calc[i].calculate_product);
t[i] = new Thread(ts);
}
//start all threads
for (int i = 0; i < 10; i++)
{
t[i].Start();
t[i].Join();
}
stop.Stop();
long seconds = stop.ElapsedMilliseconds;
MessageBox.Show("Operation Completed in: " + seconds.ToString());
}
This post has been edited by sioannou: 09 April 2011 - 11:46 AM

New Topic/Question
Reply



MultiQuote





|