reduction clause for parallel region

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

reduction clause for parallel region

Postby amritkar » Wed Jul 15, 2009 7:57 am

Hi,

I am converting a loop level paralleled code to parallel regions and can't find a reduction operation in parallel region.
Is there a convenient way of doing this or do I have to do - critical / barrier / critical - type of operation for reduction?

Thanks,
Amit
amritkar
 
Posts: 14
Joined: Tue Jun 09, 2009 5:36 am

Re: reduction clause for parallel region

Postby lfm » Thu Jul 16, 2009 8:16 am

Right now, you can do a reduction on a worksharing construct or on an entire parallel region. There are proposals to add a reduction directive for a future version of the standard. Of course, if you don't need to use the reduced value until after the parallel region then you could have multiple reduction variables. Otherwise, I'm afraid you will need to use critical sections (or atomic if your reduction fits the requirements) and barriers.

Regards,

-- Larry
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB

Re: reduction clause for parallel region

Postby amritkar » Wed Aug 12, 2009 9:50 am

Hi Larry,

How did you conclude that the reduction clause is available for work sharing constructs inside a large parallel region?
In the example below, it can be seen that I can't use reduction clause on work sharing constructs inside a parallel region.

Thanks,
Amit


Code: Select all
c Reduction unavailability in parallel region
c Amit Amritkar
c (Please vary the number of threads)   

      module data

      real,dimension(:,:,:,:),allocatable :: phi
      real reduction_glb


      end module data

   
   
      program test

      USE data
      real counter
      integer i,j,k,m
   
      allocate(phi(10,10,10,10))
   
      counter = 1.0

c$omp parallel
c$omp do private(i,j,k,m)
      do m=1,10
   
      do k=1,10
      do j=1,10
      do i=1,10
      phi(i,j,k,m)=counter
      enddo
      enddo
      enddo
      enddo
c$omp enddo
   
      call tester
   
c$omp end parallel
   
      end program test
   


      subroutine tester
   
      real summ_temp
   
c ----------------------------------------------

      interface
     
      subroutine summation(summ)
      real summ
      end subroutine summation
     
      subroutine reduction(reduce)
      real reduce
      end subroutine reduction
     
      end interface
c ----------------------------------------------

     
      summ_temp = 0.0

      call summation(summ_temp)
      write(*,*)'sum with reduction clause is:',summ_temp

      call reduction(summ_temp)
      write(*,*)'sum with critical/barrier is:',summ_temp


      end subroutine tester



      subroutine summation(summ)

      USE data
      real summ

c$omp do private(i,j,k,m)
c$omp+ reduction(+:summ)
      do m=1,10
      do k=1,10
      do j=1,10
      do i=1,10
      summ = summ + phi(i,j,k,m)
      enddo
      enddo
      enddo
      enddo
c$omp enddo     
     
      end subroutine summation

     
      subroutine reduction(reduce)

      USE data

      real reduce

c$omp critical(reduction_2)
      reduction_glb = reduction_glb + reduce
c$omp end critical(reduction_2)

c$omp barrier

c$omp critical(reduction_3)
      reduce = reduction_glb
c$omp end critical(reduction_3)

c$omp barrier
      reduction_glb = 0.0

      end subroutine reduction
amritkar
 
Posts: 14
Joined: Tue Jun 09, 2009 5:36 am


Return to OpenMP 3.0 API Specifications

Who is online

Users browsing this forum: No registered users and 2 guests

cron