http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48329

           Summary: Program takes twice as long *without* -fopenmp than
                    with 1 OpenMP thread
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: missed-optimization, openmp
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bur...@gcc.gnu.org


Program taken from http://openmp.org/forum/viewtopic.php?f=3&t=1123

System: Intel Xeon X5570  @ 2.93GHz, SUSE SLES 11 (x86_64) [glibc-2.11.1]

No OpenMP:
  gfortran -O3 -ffast-math test2.f90
  time ./a.out ->  14.44user 0.00system 0:14.46elapsed 99%CPU

With OpenMP and OMP_NUM_THREADS=1
  gfortran -fopenmp -O3 -ffast-math test2.f90
  time ./a.out ->  7.22user 0.00system 0:07.23elapsed 99%CPU

Using gfortran 4.3.4, I get the 7s result also without -fopenmp; ditto with
ifort 11.1. With OpenMP the run time of GCC 4.6 and ifort is exactly the same
[modulo noise] for 1 and 2 threads.



program calcpi
USE omp_lib
    implicit none
    double precision:: h,x,sum,pi
    integer:: n,i
    double precision:: f

   f(x) = 4.0/(1.0+x**2)

   n = 2100000000

   h= 1.0 / dble(n)
   sum = 0.0
!$OMP PARALLEL DO DEFAULT(NONE) &
!$OMP SHARED(n,h) PRIVATE(x) &
!$OMP REDUCTION(+:sum)
  DO i=1, n
     x = h * (dble(i)-0.5)
     sum = sum + f(x)
  END DO
!$OMP END PARALLEL DO
  pi = h * sum
  write(*,*) 'Pi=',pi

end program calcpi

Reply via email to