      program pb1

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 parallel-1.00  (express fortran77)
c     =================================================

c     To evaluate the trapezoidal rule estimate of the area under a curve.
      parameter (kases=1)
      integer ns(kases)
      data a,b/0.0,1.0/, ns/524288/

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

      call KXINIT
      call KXPARA(env)

c     Compute the integral of the exponential ten times for all cases.
c     Distribute the job among the nodes. The interval is divided into
c     nn subintervals and given to nodes 0, 1, etc.
      do kase = 1, kases

         kfirst = kxtime()
            n = ns(kase)
            h = (b-a)/(n-1)

c     Divide the interval (a,b) among the nodes.
      nbynn = n/nn
      aa = a + me*nbynn*h
      area = 0.0
      do i = 0, nbynn-1
         area = area + exp(aa+h*i)
      enddo

c     Now add up the area from all the nodes.
      istat = KXCOMB(area,iadd,4,1,ialnod,0,1)
      area = h*(area-(exp(a)+exp(b))/2)

      klast = kxtime()
         
      print *, 'a, b, n = ', a, b, n, ' -> area = ', area

c        Print the time spent.
         kspent = klast - kfirst
         call kmulti(6)
         print *, 'time ',float(kspent)/1000000.0, 'seconds'

      enddo
      
      stop
      end


c     Subroutine for adding. For global use.
      integer function iadd(r1,r2,isize)

      r1 = r1 + r2
      iadd = 0
      return
      end

