[Omp] Shared Variable Problem
KaveH Aasaraai
asi_ka at yahoo.com
Fri Jul 28 19:06:05 PDT 2006
Hey guys,
I'm new to this OpenMP thing. I'm facing this problem
of using a shared value, and trying to synchronize two
threads with this shared variable. Any help would
really be appreciated. Here is the problem:
i = 0;
#pragma omp parallel private(tid)
tid = omp_get_thread_num();
while(1)
{
if (!tid)
{
printf("master: i = %d\n", i);
fflush(stdout);
}
else
{
printf("worker: i = %d\n", i);
fflush(stdout);
i ++;
}
}
The "0" thread doesn't see the changes to the shared
variable, i. If I remove the while(1) thing, then the
value printed for "i" is correct. Here is a sample
(partial) output:
master: i = 0
master: i = 0
master: i = 0
worker: i = 2445
worker: i = 2446
worker: i = 2447
worker: i = 2448
worker: i = 2449
worker: i = 2450
worker: i = 2451
worker: i = 2452
Thanks to you guys in advance,
Kaveh
__________________________________________________
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