critical variable

General OpenMP discussion

critical variable

Postby billa » Tue May 06, 2008 10:14 am

Hello,

I am trying to write a code where there is a function that accesses a variable called "location" which is a random value passed to it as argument. All the threads run this function parallely.

Now i want to serealise read/writes to this variable ONLY if its value is same for any two threads. If the threads have different value for this variable, then they should work in parallel.

I would appreciate any help with this problem i have.

Thanks
billa
 
Posts: 2
Joined: Tue May 06, 2008 10:06 am

Re: critical variable

Postby ejd » Tue May 06, 2008 5:00 pm

There are two problems here.

First, the OpenMP ARB policy is to promote OpenMP - not do people's homework. While I am not a member of the ARB, since I am using their site, I will abide by their rules. I am not sure whether this is a homework problem or not, but it comes within that realm and as such I will only provide so much help.

Second, you have not really provided enough information. For example, at what point do these threads get new values or how often do the values have to be checked?

You might try putting out some code with what you have tried. That makes it easier to address problems and ask questions.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: critical variable

Postby billa » Tue May 06, 2008 10:16 pm

ejd wrote:There are two problems here.

First, the OpenMP ARB policy is to promote OpenMP - not do people's homework. While I am not a member of the ARB, since I am using their site, I will abide by their rules. I am not sure whether this is a homework problem or not, but it comes within that realm and as such I will only provide so much help.


That is a reasonably fine policy and its ok for you to abide by it. But i think u should first carefully review the post OR ask the OP (me) to clarify before declaring it such. A homework policy request would usually contain phrases like, "please give me code" or "whats wrong with my code followed by a big code" or similar (going by experiences in other educational forums)

This, however, is not the case here. I'm just asking if there exists a clause cater to my problem or if there are some standard methods/tricks to work around it using the known clauses.


ejd wrote:Second, you have not really provided enough information. For example, at what point do these threads get new values or how often do the values have to be checked?

You might try putting out some code with what you have tried. That makes it easier to address problems and ask questions.


Since you ask, i will clarify it more. I create some independent threads from a main function and continuously(inside an infinite loop) and independently call them all with the aforementioned function. Noe sure if the code could help here. If you're keen about what kind of application it is, its a part of a simulation for a coherence protocol for multiple processors and these threads each simulate a processor. In case you think some important part of code should be posted to gather more information, please let me know.
billa
 
Posts: 2
Joined: Tue May 06, 2008 10:06 am

Re: critical variable

Postby ejd » Wed May 07, 2008 5:58 am

Sorry - no insult was meant. There is no good way of stating the policy or way to review a post to see if falls into realm of the policy.

As for your problem, there are no clauses or constructs in OpenMP that will solve the problem. The variable "location" sounds as if it is going to have to be private. The problem is, that if it is private then the other threads can not see it. Somehow you must make the value visible to the other threads. One way would be to have a shared array the size of the number of threads and have each thread put it's value there (into it's array element). Unfortunately, you will have to put a barrier here to make sure all the thread's values are present before you start checking. Then each thread can check and see if two threads have the same value and if they do then you will have to do updates to the variable using critical, locks, or atomic.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: critical variable

Postby Yuan » Sat May 10, 2008 5:08 pm

billa wrote:Now i want to serealise read/writes to this variable ONLY if its value is same for any two threads. If the threads have different value for this variable, then they should work in parallel.


Could you please explain your problem in a little bit more detail? It sounds you have an interesting problem.

If 'location' is an input argument, then each thread will have a private copy. Then what do you mean by "serialize read/writes to the this variable"? Does it still matter since each thread works on its own copy? Do you want the result to be visible to all threads?

Yes, some code will definitely help here.

Thanks.

-- Yuan
Yuan
 
Posts: 2
Joined: Sat May 03, 2008 12:36 pm


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 8 guests