! OpenMP program to compute dot product of vectors X and Y
PROGRAM dotProduct

  INTEGER, PARAMETER :: N=100, CHUNKSIZE=7
  REAL :: X(N), Y(N), XdotY = 0.0
  INTEGER I

  ! initialize the vectors; parallelize just for fun
  !OMP PARALLEL DO LASTPRIVATE(X,Y)
  DO I=1,N
     X(I) = I
     Y(I) = I**2
  END DO
  !OMP END PARALLEL DO

  !OMP PARALLEL DO &
  !OMP SCHEDULE(STATIC,CHUNKSIZE) &
  !OMP REDUCTION(+:XdotY)
  DO I=1,N
     XdotY = XdotY + X(I)*Y(I)
  END DO
  !OMP END PARALLEL DO

  PRINT*, 'X.Y = ', XdotY
  PRINT*, 'Exact answer = ', (N*(N+1)/2)**2

END PROGRAM dotProduct
