On 12/22/2011 6:20 AM, Cyber Joy wrote:
> Dear all,
> I am in trouble of loop nests in OpenMP.
> ! oiginal serial codes
> !-------------------------------------------------
> ..................
> call sub(n,dk,ffk,,xi,a)
> ..................
> subroutine sub(n,dk,ffk,xi,a)
> ...
> complex(kind=8) :: a(n,n)
> dk(n),ffk(n),xi(n) computed
> complex(kind=8),external :: func
> ...
> do i=1,n
> x=xi(i)
> do j=1,n
> y=xi(n)
> a(j,k)=func1(x+y)*ffk(j)*ffk(n)*dk(k)
> end do
> end do
> do j=1,n
> x=xi(j)
> ek=x**2
> a(j,j)=ek+func(x)+a(j,j)
> end do
> end subroutine sub
> ! ------------------------------------------------
> my parallel codes are
> !------------------------------------------------
> subroutine sub(n,dk,ffk,xi,a)
> ...
> complex(kind=8) :: a(n,n)
> dk(n),ffk(n),xi(n) computed
> complex(kind=8),external :: func
> ...
> !omp parallel do private(k,x,y)
> do i=1,n
> x=xi(i)
> do j=1,n
> y=xi(n)
> a(j,k)=func1(x+y)*ffk(j)*ffk(n)*dk(k)
> end do
> end do
> !omp prallel do reduction(+:a)
> do j=1,n
> x=xi(j)
> ek=x**2
> a(j,j)=ek+func(x)+a(j,j)
> end do
> end subroutine sub
> !------------------------------------------------
> I think in the first parallel construct 'k,x,y' are private variables.
> However,it dosen't work.
> Would you guys give me some proposal?
> Thank you!
> Cyberjoy
It shouldn't work. Although it's outside Fortran (90), do private(k)
assures that k becomes undefined without an assignment inside the DO.
Is the spelling "prallel" meant to assure that the second loop doesn't
fall prey to OpenMP? There's no OpenMP reduction in that loop. If you
did make it an OpenMP parallel, the lack of private designations isn't
guaranteed to make it fail, as the compiler may optimize away the
variables which should have been private.
--
Tim Prince
|