I have written down a simple code using openmp in fixed form fortran.My code is running but the result produced by it is wrong.can anybody help me out?
Implicit none
integer i,N,CHUNKSIZE
parameter(N=100)
parameter(CHUNKSIZE=7)
double precision X(N), Y(N), XdotY
integer :: threadNUM, OMP_GET_THREAD_NUM
XdotY=0.0d0
!$OMP PARALLEL DO LASTPRIVATE(X,Y)
do I=1,N
X(I)=I
Y(I)=I**2
write(*,*) x(i),y(i)
end do
!$OMP END PARALLEL DO
!$OMP PARALLEL DO
C$OMP&REDUCTION(+:XdotY)
do I=1,N
XdotY = XdotY + X(I)*Y(I)
end do
!$OMP END PARALLEL DO
write(*,*)'X.Y=', XdotY
write(*,*)'the exact answer is =', (N*(N+1)/2.0d0)**2
end
Here the answer is not matching.
The following is the result -
X.Y= 17380000.000000000
the exact answer is = 25502500.000000000
And i am compiling it by the command - 'gfortran -fopenmp dotprod_OMP.f90 -o dotprod_OMP'.
also, i have done this in an f90 file. the following is the code - Implicit none
integer i
integer,parameter :: N=100
integer,parameter :: CHUNKSIZE=7
double precision :: X(N), Y(N), XdotY
integer :: threadNUM, OMP_GET_THREAD_NUM
XdotY=0.0d0
!$OMP PARALLEL DO LASTPRIVATE(X,Y)
do I=1,N
X(I)=I
Y(I)=I**2
!write(*,*) x(i),y(i)
end do
!$OMP END PARALLEL DO
!$OMP PARALLEL DO
!$OMP REDUCTION(+:XdotY)
do I=1,N
XdotY = XdotY + X(I)*Y(I)
end do
!$OMP END PARALLEL DO
write(*,*)'X.Y=', XdotY
write(*,*)'the exact answer is =', (N*(N+1)/2.0d0)**2
end
there is an error after compilation. the error shows this - 25 | !$OMP REDUCTION(+:XdotY) | 1 Error: Unclassifiable OpenMP directive at (1)
I think the reduction clause is not working. how can i solve this?
i=n here). Anyway, whichever the version that is retained at the end, it is incomplete.