      program hostnode

      logical okay

      call hn1 (okay)
      if (.not. okay) print *, 'ERROR : HostNode 1'
      call hn2 (okay)
      if (.not. okay) print *, 'ERROR : HostNode 2'
      call hn3 (okay)
      if (.not. okay) print *, 'ERROR : HostNode 3'
      call hn4 (okay)
      if (.not. okay) print *, 'ERROR : HostNode 4'

      end

      subroutine hn1 (okay)
      logical okay

      real a(10), ha(10), x
cmf$  layout ha(:host)

      forall (i=1:10) a(i) = i
      n = sum (a)

      ha = 0
      ha(6:10) = a(4:8)

      ha = ha + 1

      a(4:8) = ha (6:10)

      x = sum (a)
      n = n + 5
      okay = (x .eq. n)
      print *, 'Result is ', x, ' and should be ', n
      end

      subroutine hn2 (okay)
      logical okay 

      double precision a(10,10), ha(5,5), x
      integer i, j, n

cmf$  layout ha(:host)

      forall (i=1:10,j=1:10) a(i,j) = i + j
      n = sum (a)

      ha = 0
      ha = a(4:8,2:6)
      ha =  ha + 1
      a(4:8,2:6) = ha

      n = n + 5*5
      x = sum (a)
      okay = (x == n)
      print *, 'Result is ', x, ' and should be ', n
      end

      subroutine hn3 (okay)
      logical okay

      double precision a(10,10,10), ha(5,5,5), x
      integer i, j, n

cmf$  layout ha(:host)

      forall (i=1:10,j=1:10,k=1:10) a(i,j,k) = i + 2*j - k
      n = sum (a)

      ha = 0
      ha = a(4:8,2:6,5:9)
      ha = ha + 1
      a(4:8,2:6,5:9) = ha

      n = n + 5*5*5
      x = sum (a)
      okay = (x == n)
      print *, 'Result is ', x, ' and should be ', n
      end

      subroutine hn4 (okay)
      logical okay

      integer a(10,10,10,10)
      integer ha(5,5,5,10), x
      integer i, j, k, l, n

cmf$  layout ha(:host)

      forall (i=1:10,j=1:10,k=1:10,l=1:10)
        a(i,j,k,l) = i + 2*j - k + 3*l
      end forall
      n = sum(a)

      ha = 0
      ha = a(4:8,2:6,5:9,1:10)
      ha = ha + 1
      a(4:8,2:6,5:9,1:10) = ha

      n = n + 5*5*5*10

      x = sum (a)
      okay = (x .eq. n)
      print *, 'Result is ', x, ' and should be ', n
      end
