C
C Copyright (c) 1992 Carnegie Mellon University 
C                    SCAL project: Guy Blelloch, Siddhartha Chatterjee,
C                                  Jonathan Hardwick, Jay Sipelstein,
C                                  Marco Zagha
C All Rights Reserved.
C
C Permission to use, copy, modify and distribute this software and its
C documentation is hereby granted, provided that both the copyright
C notice and this permission notice appear in all copies of the
C software, derivative works or modified versions, and any portions
C thereof, and that both notices appear in supporting documentation.
C
C CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
C CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
C ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
C
C The SCAL project requests users of this software to return to 
C
C  Marco Zagha and Guy Blelloch         marco.zagha@cs.cmu.edu
C  School of Computer Science           guy.blelloch@cs.cmu.edu
C  Carnegie Mellon University
C  5000 Forbes Ave.
C  Pittsburgh PA 15213-3890
C
C any improvements or extensions that they make and grant Carnegie Mellon
C the rights to redistribute these changes.
C
      program mvmult_test
      integer rows, columns, nonzeros
      parameter (rows = 6)
      parameter (columns = 12)
      parameter (nonzeros = 32)
      real result(rows), vector(columns), fresult(rows)
      real matrix(nonzeros)
      integer indx(nonzeros)
      integer lengths(rows), pntr(rows+1), position, len
      integer descriptor(4000 + rows/64 + nonzeros/64)
      integer scratch(nonzeros)

      data (matrix(i), i=1,nonzeros) / 
     &     1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,
     &     1.0, 2.0,
C          [empty row]
     &     1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
     &     1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
     &     1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 /
      data (indx(i), i=1,nonzeros) /
     &     1, 2, 3, 4, 6, 9, 10, 11, 12,
     &     4, 8,
     &     2, 3, 4, 5, 7, 8, 12,
     &     1, 2, 4, 6, 7, 10, 11,
     &     2, 4, 5, 8, 9, 11, 12 /
      data (vector(i),  i=1,columns) /
     &     1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 
     &     7.0, 8.0, 9.0, 10.0, 11.0, 12.0 /
      data (lengths(i), i=1,rows) / 9, 2, 0, 7, 7, 7 /
      position = 1
      do 10 j=1,rows
         len = lengths(j)
         pntr(j) = position
         position = position + len
 10   continue
      pntr(rows+1) = position
      do 20 j=1,rows
         result(j) = 9999.9999
 20   continue
      call MAKEDESC(descriptor, pntr, rows, scratch)
      call MVMULT(result, matrix, vector, indx, pntr, 
     &     descriptor, rows, scratch)
      print *, 'matrix'
      print *, matrix
      print *, 'indx'
      print *, indx
      print *, 'vector'
      print *, vector
      print *, 'lengths'
      print *, lengths
      print *, 'pntr'
      print *, pntr
      print *, 'result'
      print *, result

      DO 100 I = 1,rows
c
c     Compute the inner product of row I with vector x
c
         T = 0.0
         DO 99 K = PNTR(I), PNTR(I+1)-1
            T = T + matrix(K)* vector(INDX(K))
 99      CONTINUE
c
c     Store result in Y(I)
c
         fresult(I) = T
 100  CONTINUE

      print *, 'simple fortran result'
      print *, fresult

      end
