c
c pinode.f 9.2 92/07/01 14:45:40
c
c Copyright 1991 Intel Corporation, Inc.
c See the "Copyright" file for complete rights and liability information.
c
      program pinode
      double precision h,sum,x,pi,f,a,tmp
      integer n
      integer allnodes, nodes, iam, host
      integer intsiz, dblsiz

      data allnodes / -1/
      data intsiz, dblsiz / 4, 8/
c
c
c Define the function
      f(a) = 4.0d0/(1.d0 + a*a) 

c Do some bookkeeping
      iam   = mynode()
      nodes = numnodes()
      host  = myhost()
      if(iam .eq. 0) print *,'Starting ...'
c
c Receive the number of rectangles from the host
1     continue
      if(iam .eq. 0) then
         call crecv(100,n,intsiz)
         call csend(300,n,intsiz,-1,0)
      else
         call crecv(300,n,intsiz)
      endif


c Calculate the scaling factor
      h = 1.d0/n

c Integrate.  The value of x used to calculate the slice is
c the value at the midpoint of the integration slice.
      sum = 0.d0
      do 10 i = iam+1,n,nodes
         x = h * (dble(i) -0.5d0)
         sum = sum + f(x)
10    continue
      pi = h * sum
      call gdsum(pi,1,tmp)


      if(iam .eq. 0 )then
         call csend(200,pi,dblsiz,host,100)
      endif

      goto 1
      end
