      program move2
c
c     moving two dimensional sections
c
      real a(10,10), ha(10,10), ha1(10,10)
cmf$  layout ha(:host), ha1(:host)

      real b(10), hb(10), hb1(10)
cmf$  layout hb(:host), hb1(:host)

      integer i, j, k, errors, switch

      call cmf_random (a)
      call cmf_random (b)

      ha = a
      hb = b

      print *, 'Initialisation is ready'
      print *, 'Chosse switch (1-4) : '
      read  *, switch

c     now operate on distributed arrays, make the same with host

      if (switch .eq. 1) then
         print * , 'many -> many'
         a(2,5:8) = b(3:6)
         ha(2,5:8) = hb(3:6)
      end if
c
      if (switch .eq. 2) then
         print *, 'one -> many b(2:10) = a(1:9,4)'
         b(2:10) = a(1:9,4)
         hb(2:10) = ha(1:9,4)
      end if
c
      if (switch .eq. 3) then
         print *, 'many -> one'
         a(3:8,5) = b(1:6)
         ha(3:8,5) = hb(1:6)
      end if
c
      if (switch .eq. 4) then
         print *, 'one -> one'
         a(8,9) = a(9,3)
         ha(8,9) = ha(9,3)
         b(1) = a(7,4)
         hb(1) = ha(7,4)
      end if

c     now compare distributed arrays with host arrays

      print *,'Operations are finished'

      ha1 = a
      hb1 = b
c
c     ha1 == ha ?,  hb1 == b ?

      print *,'Now checking'

      errors = 0
      do j = 1, 10
        do i = 1, 10
          if (ha(i,j) .ne. ha1(i,j)) then
             errors = errors + 1
          end if
        end do
        if (hb(j) .ne. hb1(j)) then
             errors = errors + 1
        end if
      end do

      print *, 'Errors = ', errors

      end
