c      test program for dalib_schedule
c
      program test
         call test_get1 ()
         call test_set1 ()
         call test_get2 ()
         call test_set2 ()
      end

      subroutine test_get1 ()
      parameter (N=10)
      integer A(N), B(N), P(N), HA(N)
cmf$  layout HA(:host)
      real R(N)
      forall (I=1:N) A(I) = I
c     init P by random
      call cmf_random (R)
      P = R * N + 1
      HA = P
      print *, 'TEST of GET1'
      print 10, HA
      HA = A
      call global_get (B, A, P)
c     B = A(P)
      print 11, HA
      HA = B
      print 12, HA
  10  format (' P        : ',20I3)
  11  format (' A        : ',20I3)
  12  format (' B = A[P] : ',20I3)
      end

      subroutine test_set1 ()
      parameter (N=10)
      integer A(N), B(N), P(N), HA(N)
cmf$  layout HA(:host)
      real R(N)
      forall (I=1:N) A(I) = I
      B = 0
c     init P by random
      call cmf_random (R)
      P = R * N + 1
      HA = P
      print 10, HA
      HA = A
      print 11, HA
c     B(P) = A
      print *, 'TEST of SET1'
      call global_send (B, P, A)
      HA = B
      print 12, HA
  10  format (' P        : ',20I3)
  11  format (' A        : ',20I3)
  12  format (' B[P] = A : ',20I3)
      end

      subroutine test_get2 ()
      parameter (N=10)
      integer A(3,N), B(N), P(N), Q(N), HA(N), HA1(3,N)
cmf$  layout HA(:host)
cmf$  layout HA1(:host)
      real R(N)
      forall (I=1:N,J=1:3) A(J,I) = J*10 + I
c     init P by random
      call cmf_random (R)
      P = R * 3 + 1
      call cmf_random (R)
      Q = R * N + 1
      print *, 'TEST of GET2'
      HA = P
      print 10, HA
      HA = Q
      print 11, HA
      HA1 = A
      do J = 1, 3
        print 12, HA1 (J,:)
      end do
      call global_get (B, A, P, Q)
      HA = B
      print 13, HA
  10  format (' P          : ',20I3)
  11  format (' Q          : ',20I3)
  12  format (' A          : ',20I3)
  13  format (' B = A[P,Q] : ',20I3)
      end

      subroutine test_set2 ()
      parameter (N=10)
      integer A(3,N), B(N), P(N), Q(N), HA(N), HA1(3,N)
cmf$  layout HA (:host)
cmf$  layout HA1 (:host)
      real R(N)
      forall (I=1:N) B(I) = I
      A = 0
c     init P by random
      print *, 'TEST of SET2'
      call cmf_random (R)
      P = R * 3 + 1
      HA = P
      print 10, HA
      call cmf_random (R)
      Q = R * N + 1
      HA = Q
      print 11, HA
      HA = B
      print 12, HA
      call global_send (A, P, Q, B)
      HA1 = A
      do J = 1, 3
         print 13, HA1(J,:)
      end do
  10  format (' P          : ',20I3)
  11  format (' Q          : ',20I3)
  12  format (' B          : ',20I3)
  13  format (' A[P,Q] = B : ',20I3)
      end
