[Omp] Shared Variable Problem

KaveH Aasaraai asi_ka at yahoo.com
Sat Jul 29 00:03:17 PDT 2006


Hi,

Thanks to all of you guys.

Hmmm, first, I'm a He ;)

Well, I was using only two threads in this case, but,
yes I agree it would've been better if I've said that
or had a better code. 

The other thing is, the "flush" thing solved the
problem, thanks Yuan. Also, about the synchronization,
I wasn't expecting to see a nice output, but at least
one little change on the value that master prints! :)
But I had not luck. Anyways, now it's fine using the
"flush" pragma.

Also, I guess the race condition on writing to "i"
that you were talking about Bronis, doesn't happen as
I'm using only one thread as modifier.

Thanks a lot guys, you helped so much. I didn't know
about this flush, and it was simply killing me.

Cheers,
Kaveh



--- Yuan Lin <Yuan.Lin at Sun.COM> wrote:

> Bronis,
> 
> I agree. Since KaveH did not say what he/she
> expected, I assume he/she 
> was using only two threads and was wondering why the
> value from i is not 
> updated.
> 
> I also mentioned the following in my previous reply.
> 
> > On Fri, 28 Jul 2006, Yuan Lin wrote:
> 
> >> Also depending on how the threads are scheduled,
> you may see thousands
> >> of master: i=0 before you see  worker: i=1, 2, 3,
> ...., then you may see
> >> master: i= some big number. Do not expect to see
> the value of i printed
> >> from the master be to consecutive. There is no
> synchronization between
> >> the master thread and the slave thread in your
> code.
> 
> With your email and the above text, I hope the
> reason is well explained.
> 
> Thanks.
> 
> -- Yuan
> ----------------------------------------
> http://blogs.sun.com/roller/page/yuanlin
> ----------------------------------------
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Omp mailing list