[Omp] A question about threadprivate
Dieter an Mey
anmey at rz.rwth-aachen.de
Thu Apr 12 04:32:45 PDT 2007
Sorry for generating the misunderstanding.
The "data race" concerned me and Larry answering your first mail at the
same time.
There is no data race in your code. :-)=
Actually I think that the behaviour is clearly defined by the 2.5
specification.
In case 2 the inner teams' master thread set their value of i to
-omp_get_thread_num()
which is 0 of course.
So I don't see any problem here.
Open 3.0 will hopefully be more specific about threadprivate variables
in inner parallel regions.
best regards
Dieter
Meadows, Lawrence F schrieb:
> So once again I state that the behavior in the first example is
> guaranteed by the (2.5) standard, and the behavior in the
> second is not specified.
>
> I agree that it would be nice to have both specified. I'm not sure
> where the lang committee is on that topic.
>
> -----Original Message-----
> From: Marina Kraeva [mailto:kraeva at iastate.edu]
> Sent: Wednesday, April 11, 2007 10:12 AM
> To: anmey at rz.rwth-aachen.de; Meadows, Lawrence F
> Cc: omp at openmp.org
> Subject: Re: [Omp] A question about threadprivate
>
> Dieter and Larry,
>
> Thanks for your input!
>
> I did not understand whether Dieter agreed that array is guaranteed to
> have values (0,1,2,3) in the first example, or not. And it looks like
> Dieter thinks that in the second example array is guaranteed to have
> values (-0,-0,-0,-0).
>
> I think that the behavior in both cases should be specified in API 3.0,
> or at least it should be said that that the behavior is implementation
> defined. Otherwise it won't be safe to use threadprivate and nested
> parallel in the same program.
>
> Marina.
>
> Dieter an Mey wrote:
>
>> Hi,
>>
>> In general in the nested case each thread of the inner teams will get
>> their own copies.
>> They will be initialized "at an unspecified point in the program
> porior
>> to the first reference to that copy".
>> To my understanding of the specs ...
>> In case 1 the threadprivate variable is not referenced, so it is not
>> specified whether the inner teams' slave thread's copy will be
>> initialized at all.
>> References by the inner team's master threads "will be to the copy of
>> the object in the thread which encountered the (remark: inner)
> parallel
>> region".
>> Therefore in case 2 I would expect that the inner teams' master
> threads'
>> copies will be modified in the inner parallel region.
>> Therefore array will be set to -0 for all indeces.
>>
>> best regards
>> Dieter
>>
>> Marina Kraeva schrieb:
>>
>>> Hello,
>>>
>>> Could you please share your opinion on what will happen in the
>>> following two small examples.
>>>
>>> In the OpenMP API 2.5 (and in the earlier versions) it is said:
>>> "The values of data in the threadprivate objects of threads other
> than
>>> the initial thread are guaranteed to persist between two consecutive
>>> active parallel regions only if all the following conditions hold:
>>> * Neither parallel region is nested inside another parallel
> region..."
>>>
>>> According to API, is it guaranteed that in the following example the
>>> values of 'i' will persist, so array will have values (0,1,2,3)?
>>>
>>> int i,array(0:3)
>>> threadprivate(i)
>>> !$omp parallel num_threads(4)
>>> i=omp_get_thread_num()
>>> !$omp parallel num_threads(2)
>>> ... ('i' is not referenced)
>>> !$omp end parallel
>>> !$omp end parallel
>>>
>>> !$omp parallel num_threads(4) shared(array)
>>> array(omp_get_thread_num())=i
>>> !$omp end parallel
>>>
>>>
>>>
>>> What if inside the nested parallel region 'i' was modified:
>>>
>>> int i,array(0:3)
>>> threadprivate(i)
>>> !$omp parallel num_threads(4)
>>> i=omp_get_thread_num()
>>> !$omp parallel num_threads(2)
>>> i=-omp_get_thread_num()
>>> !$omp end parallel
>>> !$omp end parallel
>>>
>>> !$omp parallel num_threads(4) shared(array)
>>> array(omp_get_thread_num())=i
>>> !$omp end parallel
>>>
>>> Is it guaranteed, that array still will have values (0,1,2,3)?
>>>
>>> Thank you!
>>> Marina Kraeva.
>>> _______________________________________________
>>> Omp mailing list
>>> Omp at openmp.org
>>> http://openmp.org/mailman/listinfo/omp
>>>
>
--
--------------------------------------------------------------------
Dieter an Mey
High Performance Computing Hochleistungsrechnen
RWTH Aachen University Rechen- und Kommunikations-
Center for Computing and Communication zentrum der RWTH Aachen
phone: ++49-(0)241-80-24377 Seffenter Weg 23
fax: ++49-(0)241-80-22134 52074 Aachen, Germany
email: anmey at rz.rwth-aachen.de
--------------------------------------------------------------------
More information about the Omp
mailing list