Four threads are generated and passed their range needed to loop a matrix in order to do some operation. Essentially, my desire is to take a for loop and break up the work by four threads.
GE_threaddiv t = new GE_threaddiv(k + 1,toPass + (k+1),k,A[k][k],"1");
GE_threaddiv t2 = new GE_threaddiv(toPass + (k+1),toPass*2 + (k+1),k,A[k][k],"2");
GE_threaddiv t3 = new GE_threaddiv(toPass*2 + (k+1),toPass*3 + (k+1),k,A[k][k],"3");
GE_threaddiv t4 = new GE_threaddiv(toPass*3 + (k+1),toPass*4 + (k+1),k,A[k][k],"4");
t.start();
t2.start();
t3.start();
t4.start();
try {
t.join();
t2.join();
t3.join();
t4.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Each thread starts a for loop with the specified range a being the start and b being the end of the segment (passed in when the thread was made). A is a global matrix and temp is a value from A passed into the thread on creation.
public void run()
{
try
{
for(int j = a; j < b; j++) {
A[c][j] = A[c][j]/temp;
}
}
catch (Exception e)
{
System.out.println ("Exception is caught");
}
}
My implementation is working, however it is drastically slower (magnitudes) than if I were to run the for loop in serial. The larger the data set, the slower the time. The threads are confirmed to be running side by side. My guess is that the degradation in efficiency is coming from how each thread is involved with memory access. Any help would be greatly appreciated!