
September 2nd, 2009, 02:39 PM
#1
how to implement barrier?
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

September 3rd, 2009, 08:16 AM
#2
Re: how to implement barrier?
What is your actual question? You just posted your pseudo code and a vague description of the problem. We here are not going to write the method implementations for you, so do you have any code for those methods yet? Are you having problems deciding where to start?

September 3rd, 2009, 08:45 AM
#3
Re: how to implement barrier?
So far all i can see is a red and white board based with each squares colour based on whther a number is odd or not? So what are you doing with it? Scratch that ill just observe i get it now

September 3rd, 2009, 03:12 PM
#4
Re: how to implement barrier?
well guyz my question is how to implement barrier that will od this:
IMPORTANT THING is that 1st method and 3rd method need to finish and when they both finish 2nd method and 4th method can start execution... (look down how methods r set...)
1st thread:
do 1st method (anythindoesnt matter)
BARIER (wait till 1st and 3rd finish)
do 2nd method (anything doesnt matter)
BARIER(wait till 2nd and 4th finish)
recursive call of 1st thread again
2nd thread:
do 3rd method (anythindoesnt matter)
BARIER (wait till 1st and 3rd finish)
do 4th method (anything doesnt matter)
BARIER(wait till 2nd and 4th finish)
recursive call of 2nd thread again
all methods are writen already but i didnt want to complicate things up....
i just need idea how to make this barrier...
i wrote those thing abput red/black points cuz i thought u will understain problem easier...
thanx

September 4th, 2009, 10:54 AM
#5
Re: how to implement barrier?
By barrier are you trying to say that you need to make the matrix synchronized so that multiple threads don't overwrite each others work while performing actions on it?

September 5th, 2009, 10:45 AM
#6
Re: how to implement barrier?
exactly that

September 5th, 2009, 03:14 PM
#7
Re: how to implement barrier?
How about using a java.util.concurrent.CyclicBarrier

September 8th, 2009, 08:28 AM
#8
Re: how to implement barrier?
keang has suggested using a class that is designed to be thread safe (hence it being in the concurrent package).
As a matter of fact, if you look at the api for this class, it gives an example of exactly what you are trying to do (well, almost exactly).
Tags for this Thread
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
OnDemand Webinars (sponsored)
