      program pb3

c     Reference:
c     Problems to test parallel and vector languages
c     CSD-TR 516, computer science, Purdue University
c     John R. Rice, may 1, 1985
c
c     Revised by John R. Rice and J. Jing, oct. 1, 1990
c
c     *************************************************
c     *      Adapted for FORTRAN D benchmarking       *
c     *    by  T. Haupt  (haupt@sccs.npac.syr.edu)    *
c     *        Assisted by B. S. Balakrishna          *
c     *                                               *
c     *    Northeast Parallel Architectures Center    *
c     *   at Syracuse University, Syracuse, NY, USA   *
c     *************************************************
c
c     Version sequential-1.00  (express fortran77)
c     =================================================

c     To compute the sum over rows of the product over columns of
c     a certain matrix.
      parameter (kases=1)
      integer ns(kases), ms(kases)
      parameter (ndim=512,mdim=512)
      real a(ndim,mdim), p(ndim)
      data ns/512/, ms/512/

      integer env(4)
      common/xpenv/ env
      common/xpress/nocare,norder,nonode,ihost,ialnod,ialprc
      equivalence (env(1),me), (env(2),nn)
      external isum

      call KXINIT
      call KXPARA(env)

c     Distribute the rows among the nodes. Node 0 handles the first
c     n/nn rows, node 1 the next n/nn rows, etc.
      do kase = 1, kases
         n = ns(kase)
         m = ms(kase)
         mlocal = m/nn

         kfirst = kxtime()

c     Initializing the matrix.
      do i = 1, n
         do j = 1, mlocal
            a(i,j) = 1.000
         enddo
      enddo

c     Computing the sum of products.
      do j = 1, mlocal
         p(j) = 1.0
         do i = 1, n
             p(j) = p(j)*a(i,j)
         enddo
      enddo

      sum = 0
      do j = 1, mlocal
         sum = sum + p(j)
      enddo
c     Now combine the results from all the nodes.
      istat = KXCOMB(sum,isum,4,1,ialnod,0,1)

         klast = kxtime()

c        Print the result.
         print *, 'n, m = ', n, m, ' -> ', 'sum = ', sum
         
c        Print the time spent.
         kspent = klast - kfirst
         call kmulti(6)
         write(6,*) 'time', float(kspent)/1000000.0,' seconds'
         call kflush(6)
      enddo

      stop
      end


      integer function isum(r1,r2,isize)

      r1 = r1 + r2
      isum = 0
      return
      end

