c
c piserial.f 9.2 92/07/01 14:45:44
c
c Copyright 1991 Intel Corporation, Inc.
c See the "Copyright" file for complete rights and liability information.
c
c Serial (non-parallel) version of program to calculate pi.
c Runs on host computer alone; provided for comparison with node program.
c
      program pi
      double precision h,sum,x,pi,f,a
      integer n
c
c Define the function
      f(a) = 4.0d0/(1.d0 + a*a) 

c Input the number of intervals. 
1     print *,' Enter number of intervals:' 
      read(5,*,end=100) n 


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 = 1,n
         x = h * (dble(i) -0.5d0)
         sum = sum + f(x)
10    continue
      pi = h * sum
c 
c Output the answer 
      print *,' The value of pi for',n,' intervals is',pi 
      goto 1 
c 
c Terminate 
100   stop 
      end
