home *** CD-ROM | disk | FTP | other *** search
- subroutine pi(a,b,points)
- c Variables:
- c
- c points Number of points used in the integration. Input by the user
- c a Lower limit of integration
- c b Upper limit of integration
- c x Independent variable of integration
- c f Function to integrate
- c slicesize Size of integration slice
- c partialint Partial integral calculated on node
- c integral Calculated integral
- c
-
- c Calls:
- c
- c func to evaluate the function f(x) being evaluated
-
- integer points
- integer i(points), j
- double precision x(points)
- double precision partialint(points)
- double precision slicesize, integral, a, b
- double precision f(points)
- real busy1, busy2
-
- call CM_timer_clear(0)
- call CM_timer_start(0)
- call walltime (busy1)
-
- integral = 0.0 !initialization(front-end)
- c calculate slice size (front end):
- slicesize = (b - a) / points
- i = [1:points] !array constructor(CM)
- x = a + (i - 0.5)*slicesize !array expression(CM)
-
- c each processor calculates the partial integral
- call fun(f,x,points)
- partialint = f * slicesize !inprocessor operation(CM)
- integral = sum(partialint) !sum reduction function(CM operation
- !that ends up with a scalar passed to the front-end)
-
- call CM_timer_stop(0)
- call walltime (busy2)
-
- call CM_timer_print(0)
- busy1 = busy2 - busy1
- write(6,*) 'MFLOPS = ', points*8/(busy1*10**6)
- write(6,*) 'Sum = ',integral
- write(6,*) 'Error = ',integral-3.14159265358979323846
-
- return
- end
-
-