Data sharing attribute in a task contruct

Discuss the OpenMP 3.0 API Specifications with the OpenMP Arch. Review Board. (Read Only)

Data sharing attribute in a task contruct

Postby m_van_waveren » Fri Jun 25, 2010 10:17 am

We at Fujitsu have a question concerning the data sharing attribute in a task construct.

On the bottom of the page 79, there are following two statements.

- In a task construct, if no default clause is present, a variable
that is determined to be shared in all enclosing constructs, up to
and including the innermost enclosing parallel construct, is
shared.
- In a task construct, if no default clause is present, a variable
whose data-sharing attribute is not determined by the rule above
is firstprivate.

But we think it does not specify the rule when the task construct is not
included in any parallel constructs.

When no parallel construct is including, is variables firstprivate ? We
don't think it well-defined. We guess as follows. Can someone confirm this ?

- In a task construct, if it is not included in any parallel
construct, variables that satisfies both of the following conditions are
"shared". Otherwise, "firstprivate"
- variables defined as "shared" by the rule in 2.9.1.2. or
dummy/formal arguments that are passed by reference
- if the task clause is included by some other clauses,
and all of the outer clauses defines the variable as
"shared"

sample4: task construct (orphaned construct)
--------------------------------------------------------------
subroutine sub
integer :: a ! "a" is private in this region.
integer,save :: b ! "b" is shared in this region.
!$omp task
a = 1 ! "a" is firstprivate.
b = 1 ! "b" is shared.
!$omp end task
end
----------------------------------------------------------------

sample5: nested task construct (orphaned construct)
----------------------------------------------------------------
subroutine sub
integer :: c = 1 ! "c" is shared in this region.
integer :: d ! "d" is private in this region.
integer,save :: e ! "e" is shared in this region.
!$omp task shared(c,d) private(e)
! "c" and "d" are shared,
! "e" is private at here.
!$omp task
c = 1 ! "c" is shared.
d = 1 ! "d" is firstprivate.
e = 1 ! "e" is firstprivate.
!$omp end task
!$omp end task
end
----------------------------------------------------------------

sample6: inherit from associated actual argument (3)
----------------------------------------------------------------
program test1
integer :: a
a = 10
!$omp parallel shared(a) ! "a" is shared in this parallel region.
call sub(a)
!$omp end parallel
end

subroutine sub(x)
integer :: x ! "x" refers "a" (associated actual argument).
!$omp task
x = 2 ! "x" is shared. ("x" refers "a")
!$omp task
x = 3 ! "x" is shared. ("x" refers "a")
!$omp end task
!$omp end task
end
---------------------------------------------------------------

sample7: inherit from associated actual argument (4)
----------------------------------------------------------------
program test2
integer :: b
!$omp parallel private(b)
! "b" is private in this parallel region.
b = 20
call sub(b)
!$omp end parallel
end

subroutine sub(y)
integer :: y ! "y" refers "b" (associated actual argument).
!$omp task
y = 2 ! "y" is shared. ("y" refers "b")
!$omp task
y = 3 ! "y" is shared. ("y" refers "b")
!$omp end task
!$omp end task
end
---------------------------------------------------------------
m_van_waveren
 
Posts: 9
Joined: Tue Dec 11, 2007 12:57 pm
Location: Toulouse, France

Re: Data sharing attribute in a task contruct

Postby Federico » Fri Jun 25, 2010 1:32 pm

This is going to be clarified in the next version of the standard.
The correct interpretation is that what is predetermined or implicitly determined shared in the innermost scope (or scoping unit) enclosing the task construct is also shared in the latter.
Everything else is determined firstprivate, dummy arguments included.
Federico
 
Posts: 22
Joined: Wed Oct 24, 2007 6:39 am

Re: Data sharing attribute in a task contruct

Postby Federico » Thu Jul 01, 2010 1:10 pm

The interpretations in examples 4 and 5 are correct.
The one for 6 and 7 are not: as there is no way to know whether an actual argument is shared or private, the only safe choice is to make "x" and "y" firstprivate by default.
Federico
 
Posts: 22
Joined: Wed Oct 24, 2007 6:39 am


Return to OpenMP 3.0 API Specifications

Who is online

Users browsing this forum: No registered users and 3 guests