[Omp] Threadprivate variables and nested parallelism
Haab, Grant
grant.haab at intel.com
Wed Dec 13 10:34:08 PST 2006
Larry,
I think the implementation you describe would no longer work in this
circumstance. Shared clauses for threadprivate objects could be
implemented by calls to a run-time library that maintains a hash table
that takes as input some global thread identfier + original variable
address and returns the corresponding threadprivate variable address.
The mapping in the hash table for threadprivate object would have to be
modified at the start and end of each nested parallel region with that
object listed in its "shared" clause.
- Grant
-----Original Message-----
From: omp-bounces at openmp.org [mailto:omp-bounces at openmp.org] On Behalf
Of Meadows, Lawrence F
Sent: Wednesday, December 13, 2006 11:04 AM
To: James Beyer; anmey at rz.rwth-aachen.de
Cc: omp at openmp.org
Subject: RE: [Omp] Threadprivate variables and nested parallelism
One way to implement threadprivate is with the compiler
replacing the variable with a pointer to an array that
is indexed by thread number. So if you are in a nested
parallel region that wants the variable to be shared,
and in a subroutine that is not in the lexical extent
of a data sharing attribute directive that marks the
variable shared, how does the compiler know that it is
really shared and not threadprivate, and how do you
reference that variable?
Something like (pardon my Fortran, C would be the same):
common /fubar/ a(n)
!$omp threadprivate(/fubar/)
!$omp parallel copyin(/fubar/)
call sub1
!$omp end parallel
subroutine sub1
common /fubar/ a(n)
!$omp threadprivate(/fubar/)
!$omp parallel shared(a)
call sub2
!$omp end parallel
end
subroutine sub2
common /fubar/ a(n)
... a(1) ...
! what do we do here? If we call /fubar/ threadprivate, we must do one
thing.
! if we don't, what do we do? Make a 'global' copy of /fubar/? But that
! can't be right, because each nested team wants its own copy.
end
-----Original Message-----
From: omp-bounces at openmp.org [mailto:omp-bounces at openmp.org] On Behalf
Of James Beyer
Sent: Wednesday, December 13, 2006 8:13 AM
To: anmey at rz.rwth-aachen.de
Cc: omp at openmp.org
Subject: Re: [Omp] Threadprivate variables and nested parallelism
Ok, I am confused. If you want all of the threads to share the same
data why is it in the threadprivate list? Or are you talking about
nested parallelism where the outer parallel region has the data in
threadprivate and the inner parallel region has the data shared? If
this is the case I don't see why there would be a problem with this. Of
course I may change my opinion as I begin bringing full support for
nested parallelism on line in our compiler.
james
Dieter an Mey wrote:
> Well, you now, Larry, that we are happily profiting from nested
> parallelism, where tasks would not be the right solution.
>
> And providing copies of large chunks of data for all threads of the
> inner teams can be a waste of memory...
>
> But I understand that implementing the feature to share threadprivate
> data may be painful - but I am just a stupid user ...
>
> Dieter
>
>
> Marina Kraeva schrieb:
>> Dieter and Lawrence,
>>
>> Thank you for the clarification.
>>
>> Lawrence, I feel your pain :)
>>
>> Marina.
>>
>> Meadows, Lawrence F wrote:
>>
>>>
>>> Dieter, I'm sure that your interpretation is correct. Every
>>> thread gets its own copy.
>>>
>>> So if it is "unfortunate" then you would want to be able to
>>> make a threadprivate variable shared in an inner team (using
>>> an explicit shared clause on the parallel directive, I
>>> assume). I have no idea how hard this would be to implement
>>> and I don't like it.
>>>
>>> I wish we could just drop nested parallelism... and threads...
>>>
>>> -----Original Message-----
>>> From: omp-bounces at openmp.org [mailto:omp-bounces at openmp.org] On
Behalf
>>> Of Dieter an Mey
>>> Sent: Tuesday, December 12, 2006 9:31 AM
>>> To: Marina Kraeva
>>> Cc: omp at openmp.org
>>> Subject: Re: [Omp] Threadprivate variables and nested parallelism
>>>
>>> My understanding is that all threads will get there own copy - even
>>> threads of the inner team (unfortunately).
>>>
>>> Dieter
>>>
>>> Marina Kraeva schrieb:
>>>
>>>> Hello,
>>>>
>>>> I could not find in API 2.5 what will happen if a threadprivate
>>>
>>> variable
>>>> is referenced within a nested parallel region, other than this:
>>>>
>>>> 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.
>>>>
>>>>
>>>> I would think that each thread of the initial team (created for the
>>>> nesting parallel region) will create a new team, and the
threadprivate
>>>
>>>
>>>> copy of this thread will become shared among threads in the new
team
>>>
>>> in
>>>> the nested parallel region (so there will be NT shared variables,
>>>
>>> where
>>>> NT is the number of threads in the nesting parallel region).
>>>>
>>>> Am I correct assuming this? Can I count on this behavior or it's
>>>
>>> undefined?
>>>
>>>> Thank you,
>>>> Marina Kraeva.
>>>> _______________________________________________
>>>> Omp mailing list
>>>> Omp at openmp.org
>>>> http://openmp.org/mailman/listinfo/omp
>>>>
>>>
>>>
>>
>
_______________________________________________
Omp mailing list
Omp at openmp.org
http://openmp.org/mailman/listinfo/omp
_______________________________________________
Omp mailing list
Omp at openmp.org
http://openmp.org/mailman/listinfo/omp
More information about the Omp
mailing list