       program pschedule
c
#include "mpi.fort.h"
c
       integer i,ndata,indirection, BUFSIZE, my_size
       parameter(BUFSIZE = 4)
       integer my_index(5),global_ref(5),local_ref(5)
       double precision x(5),y(5+BUFSIZE)
       integer tabptr,schedptr, build_translation_table
       integer parti_create_hash_table
       integer parti_make_mask
       integer hashptr
       integer istamp, imask, ndont_care, n_off_proc
c data initialization
       if(MPI_mynode().eq.0) then
         my_index(1) = 2
         my_index(2) = 3
         my_index(3) = 6
         my_size = 3
         global_ref(1) = 4
         global_ref(2) = 8
         global_ref(3) = 2
         global_ref(4) = 1
         ndata = 4
       else if(MPI_mynode().eq. 1) then
         my_index(1) = 1
         my_index(2) = 4
         my_index(3) = 5
         my_index(4) = 7
         my_index(5) = 8
         my_size = 5
         global_ref(1) = 5
         global_ref(2) = 3
         global_ref(3) = 4
         global_ref(4) = 1
         global_ref(5) = 7
         ndata = 5
        else
         my_size = 0
         ndata = 0
        end if
        do 20 i=1,my_size
           x(i) = my_index(i)
           y(i) = 2*my_index(i)
20       continue
C initialize CHAOS environment
        call PARTI_setup()
c the following is the inspector code
         tabptr = build_translation_table(1,my_index,my_size)
         hashptr =  PARTI_create_hash_table(8)
         call PARTI_hash(tabptr,hashptr,-1,istamp,global_ref,
     $      ndata, my_size, ndont_care, n_off_proc)
c
c The stamp returned by PARTI_hash is an integer between 1 and 32.
c PARTI_make_mask maps this integer into a  specific bit in an integer mask
c masks can then be bit-OR'ed if needed.
c
         imask =  PARTI_make_mask(istamp)
         call PARTI_schedule(hashptr, imask, schedptr, 1)
c
c  end of the inspector and the executor begins
         call dgather(y(my_size+1),y,schedptr)
         do 30 i=1,ndata
           indirection = global_ref(i)
           x(i) = x(i) +  y(indirection)
30       continue

         if (MPI_mynode().eq.0) then
         WRITE(*,*) 'Processor 0'
         WRITE(*,*) (X(I), I=1,my_size)
         end if
         call MPI_gsync()
         if (MPI_mynode().eq.1) then
         WRITE(*,*) 'Processor 1'
         WRITE(*,*) (X(I), I=1,MY_SIZE)
         end if

	end
