program int_pi
c
c This simple program approximates pi by computing pi = integral
c from 0 to 1 of 4/(1+x*x)dx which is approximated by sum from
c k=1 to N of 4 / ((1 + (k-1/2)**2 ).  The only input data required is N.
c
c NOTE: Comments that begin with "cspmd" are hints for part b of the
c       lab exercise, where you convert this into a PVM program.
c
cspmd  Each process could be given a chunk of the interval to do.
c
       real err, f, pi, sum, w
       integer i, N
       f(x) = 4.0/(1.0+x*x)
       pi = 4.0*atan(1.0)
       N = 1000
       print *,'Approximation intervals, N, is set to 1000'

cspmd  call startup(mynum)

       w = 1.0/N
       sum = 0.0
       do i = 1,N
  sum = sum + f((i-0.5)*w)
       enddo
       sum = sum * w
       err = sum - pi
       print *, 'sum, err =', sum, err
       end

       subroutine startup (mynum)
cspmd When parallelizing programs, it is convenient to put startup code
cspmd into a separate subroutine.  This startup routine contains all the
cspmd logic for starting up both the nost AND the node programs.
cspmd This is the SPMD model of programming.
c
c    This is a good place to enroll yourself, returning "mynum"
c
       return
       end