Question about OpenMP attribute of index variables.

Question about OpenMP attribute of index variables.

amat000的头像

Hello,

I have a question about OpenMP attribute of index variables in a Region but not in constant.

The specification of OpenMP3.0 said,

2.9.1.2 Data-sharing Attribute Rules for Variables Referenced in a
Region but not in a Construct

-- Fortran --
implied-do indices, forall indices, and other local variables declared in called
routines in the region are private.

I believe index i in the comp subroutine as follows should be private,  but it is shared.

       program test
       parameter (N=400)
       common/tmp/i,j,k
       real a(N,N),b(N,N),c(N,N)

!$omp parallel do
       do j=1,N
       do i=1,N
         a(i,j)=real(i)
         b(i,j)=real(i+j)
         c(i,j)=0.0
       enddo
       enddo
!$omp parallel do
       do j=1,N
       do k=1,N
          call comp(a,b,c,N)
       enddo
       enddo

       write(*,*) c(N,N)
       stop
       end

       subroutine comp(a,b,c,N)
       common/tmp/i,j,k
       real a(N,N),b(N,N),c(N,N)
       integer omp_get_thread_num
       do i=1,N
         write(omp_get_thread_num()+200,*) i
         c(i,j)=c(i,j)+a(i,k)*b(k,j)
       enddo
       return
       end

After this program was launched with 32 threads, I checked the head of fort.2?? files.
==> fort.223 <==
           1
         222
         223
         224
         225

The correct values are
           1
           2
           3
           4
           5

compiler version : Intel 64 13.0 Build 20120731
processors         : E7-8837@2.67GHz
OS                    : SLES 11SP1
 
Could you check out this issue, please?

Best rergards,
Akiko MATSUMOTO

5 帖子 / 0 new
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
IanH的头像

i is in common and it is not a loop iteration variable for a do loop associated with a do or parallel do construct. "Variables belonging to common blocks ... and referenced in called routines in the region are shared unless they appear in a threadprivate directive."

amat000的头像

IanH-san,

Thank you for your reply.

I understand what you said, but I believe index i should be private.
Because
1. The index variable k in my sample program is private ( k is in common).
2. As you said Openmp specification said "Variables belonging to common blocks ... ",
but I can read the last sentence means do-loop/forall indices are exception.

best regards,
Akiko MATSUMOTO

IanH的头像

An implied-do is not the same as a do loop. An implied do is something like

(..., i = 1, 10)
, as you may find in array constructors, data statements and input/output statements.

Inside comp, j and k should also be shared. They will have undefined values. Have a read of A.32.

amat000的头像

IanH-san,

I really understand what you mean.
An implied-do is not the same as a do loop. I didn't know the difference of a implied-loop and a do loop.
Thank you so much for your helpful answer.

Akiko MATSUMOTO

登陆并发表评论。