OpenMP Working Precision Doubt.

General OpenMP discussion

OpenMP Working Precision Doubt.

Postby eleteroboltz » Sat Jul 20, 2013 5:59 pm

I am having an issue with the simple code bellow. I am trying to use OpenMP with GFortran. The Results of the code bellow for x should be the same with AND without !$OMP statements, since the parallel code and serial code should output the same result.

Code: Select all
program test
implicit none
integer i,j
Real(8) :: x,t1,t2

x=0.0d0
!$OMP PARALLEL DO PRIVATE(i,j) shared(X)
Do i=1,3
   Write(*,*) I
   !pause
   Do j=1,10000000
   !$OMP ATOMIC
    X=X+2.d0*Cos(i*j*1.0d0)
   end do
end do
!$OMP END PARALLEL Do

write(*,*) x   
end program test


But strangely I am getting the following results for x:

Parallel:-3.17822355415XXXXX

Serial: -3.1782235541569084

where XXXXX is some random digits. Every time I run the serial code, I get the same result (-3.1782235541569084). How can i fix it? Is this problem due to some OpenMP working precision option?
eleteroboltz
 
Posts: 2
Joined: Wed Aug 08, 2012 2:58 pm

Re: OpenMP Working Precision Doubt.

Postby MarkB » Mon Jul 22, 2013 2:44 am

Hi there,

eleteroboltz wrote: Is this problem due to some OpenMP working precision option?


I don't think so. It is simply that the answer you get for this computation is sensitive to the order in which you perform the additions, due to the accumulation of the floating point rounding errors. If you run code sequentially with the j loop in reverse (i.e. Do j=10000000,1,-1 ) then you will also get a different result.

Hope that helps,
Mark.
MarkB
 
Posts: 422
Joined: Thu Jan 08, 2009 10:12 am

Re: OpenMP Working Precision Doubt.

Postby eleteroboltz » Mon Jul 22, 2013 6:23 pm

You are totally right, Mark.

Thank you
eleteroboltz
 
Posts: 2
Joined: Wed Aug 08, 2012 2:58 pm


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 11 guests