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) cspmd call startup(mynum) c c Now solicit a new value for N. When it is 0, then you should depart. cspmd This would be a good place to unenroll yourself as well. 5 continue print *,'Enter number of approximation intervals:(0 to exit)' read *, N if (N .le. 0) then call exit endif 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 go to 5 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