      program move3

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

      real b(10,10), hb(10,10), hb1(10,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-6) : '
      read  *, switch

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

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

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

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

      if (switch .eq. 5) then
         print *, 'full contiguous'
         b(1:10,2:8) = a(1:10,3:9,4)
         hb(1:10,2:8) = ha(1:10,3:9,4)
      end if

      if (switch .eq. 6) then
         print *, 'shifting in dim1'
         a(2:9,2:9,1:8) = a(2:9,2:9,2:9)
         ha(2:9,2:9,1:8) = ha(2:9,2:9,2:9)
      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 (this may take a while)'

      errors = 0
      do k = 1, 10
       do j = 1, 10
        do i = 1, 10
          if (ha(i,j,k) .ne. ha1(i,j,k)) then
             print *, 'HA for i, j, k = ', i, j, k
             errors = errors + 1
          end if
        end do
        if (hb(j,k) .ne. hb1(j,k)) then
             print *, 'HB for j, k = ', j, k
             errors = errors + 1
        end if
       end do
      end do

      print *, 'Errors = ', errors

      end
