For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2007 > Different results with same executable using openmp clause









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Different results with same executable using openmp clause
anshu.bhola@gmail.com

2007-03-25, 8:03 am

Hello friends,

I am using a openmp reduction clause in fortran program.

please consider the program below.

-----------------------------------------------------------------------
integer :: y
y=0
!$omp parallel
!$omp do reduction(+:y)
do i = 1,1000
y = y + i;
enddo
!$omp enddo
!$omp do
do i = 1,1000
y = y - i
enddo
!$omp end parallel
print *, "Should be ", y
end
--------------------------------------------------------------------------
I compiled this program with gfortran like this
gfortran -fopenmp abc.f90

Now the problem is that the executable a.out gives different output
everytime.
like
Should be 12505
Should be 16304
Should be 18580
Should be 0

According to me it should be 0

Can you please tell me if this is normal behavior with openmp clause
or is it some bug with gfortran


Regards
Anshu

FX

2007-03-25, 8:03 am

> integer :: y
> y=0
> !$omp parallel
> !$omp do reduction(+:y)
> do i = 1,1000
> y = y + i;
> enddo
> !$omp enddo
> !$omp do
> do i = 1,1000
> y = y - i
> enddo
> !$omp end parallel
> print *, "Should be ", y
> end

[...]
> Can you please tell me if this is normal behavior with openmp clause or
> is it some bug with gfortran


I'm not an OpenMP expert, but I suspect you're missing a reduction clause
in your second do loop.

--
FX
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com