! CSC/PATC Introduction to parallel programming using MPI and OpenMP
! (c) CSC 2013

program vectorsum
  implicit none
  integer, parameter :: rk = kind(1d0)
  integer, parameter :: ik = selected_int_kind(9)
  integer, parameter :: nx = 102400

  real(kind=rk), dimension(nx) :: vecA, vecB, vecC
  real(kind=rk)    :: sum
  integer(kind=ik) :: i

  ! Initialization of vectors
  do i = 1, nx
     vecA(i) = 1.0_rk/(real(nx - i + 1, kind=rk))
     vecB(i) = vecA(i)**2
  end do

  ! TODO:
  !   Implement here the parallelized version of vector addition,
  !   vecC = vecA + vecB

  ! Compute the check value
  write(*,'(A,G0)') 'Reduction sum: ', sum(vecC)

end program vectorsum
