      program indirect

c     test bed for indirect addressing, here switch

      integer N
      parameter (N = 16)
      integer A(N), B(N), P(N)
      integer HA (N)
cmf$  layout HA(:host)

      integer I
c

c     init A
      forall (I=1:N) A(I) = I

c     make P to a switch vector

!HPF$ INDEPENDENT, LOCAL_ACCESS
      do I = 1, N 
         X = mod (I-1,4)
         if (X .ge. 2) then
           X = I - 2
          else
           X = I + 2
         end if
         P(I) = X
      end do
          
c
      HA = P
      print *, 'P = ', HA

      B = A(P)
      HA = B
      print *, 'B = A[P]', HA

      end
