hello all...

i need help with some barrier... The idea of program is parrallel red/black SOR method (if smbdy knows what i am talking about), which is doing some calculations in matrix(matrix[i][j])... we have 2 phases, red and black... both are calculating (diferent) points in matrix, red is calculating if(i+j%2=0--->red points), bla bla and other ones if(i+j%2=0--->black points) ... main point is that they calculate different points...
i need to make that parrallel... so i have an idea to make just 2 threads, first 1 is calculating just points in upper half of matrix (red and black just barier between) and second lower half of matrix (again both red and black points). That would make program quicker, but biggest problem is that first whole red points have to be calculated (need to have barier, so both threads finish) and than black ones start to calculate and so on...

down is some kind of pseudo code for help...

my program is like this:

class calculations{

calculations1a() {...}

calculations1b() {...}

calculations2a() {...}

calculations2b() {...} // all 4 similar methods

//+other methods...

main(){ //this is whole text in main... just starting both threads...

Thread thread1 = new thread1();
Thread thread2 = new thread2();

thread1.start();
thread2.start();
}



class thread1{

run(){

// 1 is red phase, a is upper half of matrix
// 2 is black phase, b is lower half of matrix

calculations.calculations1a(); //thread1 calculates upper half of red points(need to wait calculations1b, that is in thread2 and than continue for calculations2a), same for other methods

BARRIER(); //need to wait for calculations1b --> so all red points r calculated

calculations.calculations2a();

}
}


class thread2{

run(){

calculations.calculations1b();

BARRIER();

calculations.calculations2b();
}
}


i hope any1 will understain my problem, if u need any more details or have some questions plz ask...


thanx