[Omp] atomic and flush

Nils Smeds smeds at pdc.kth.se
Tue Nov 16 07:18:23 PST 2004


I think it is a bug. Also, depending on the size of the code in the loop
it might be advantageous to use a temporary number_access variable unless 
there is
a very efficient atomic sum instruction that your OpenMP implementation takes 
use of. I sketched this usage below.

Also, INDEX is accessed in a way that may impede performance, but only to a low
degree (if it is only read in the parallel section) and the ordering of the 
numbers i INDEX may have a large impact on your performance (both positive and
negative).

C$OMP PARALLEL SHARED(INDEX,number_access,N)
C$OMP+PRIVATE(i,re,myid,p,loc_number_access)

       do i=min_index,max_index
         loc_number_access(i)=0
       end do

       myid=OMP_GET_THREAD_NUM()
       p=OMP_GET_NUM_THREADS()

       do i=myid+1,N,p
           re=INDEX(i)
           .....

           loc_number_access(re)=loc_number_access(re)+1
           .....

       enddo

C$OMP CRITICAL
       do i=min_index,max_index
          number_access(i)=number_access(i)+loc_number_access(i)
       end do
C$OMP END CRITICAL

C$OMP END PARALLEL






More information about the Omp mailing list