home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / adaptor / examples / hpf_gen / pi / pi.fcm < prev    next >
Encoding:
Text File  |  1993-03-23  |  1.8 KB  |  54 lines

  1.     subroutine pi(a,b,points)
  2. c   Variables:
  3. c
  4. c       points          Number of points used in the integration. Input by the user
  5. c       a               Lower limit of integration
  6. c       b               Upper limit of integration
  7. c       x               Independent variable of integration
  8. c       f               Function to integrate 
  9. c       slicesize       Size of integration slice
  10. c       partialint      Partial integral calculated on node
  11. c       integral        Calculated integral
  12. c
  13.  
  14. c   Calls:
  15. c
  16. c       func           to evaluate the function f(x) being evaluated
  17.  
  18.         integer points
  19.         integer i(points), j
  20.         double precision  x(points)
  21.     double precision partialint(points)
  22.     double precision  slicesize, integral, a, b 
  23.         double precision f(points)
  24.         real busy1, busy2
  25.  
  26.                 call CM_timer_clear(0)
  27.                 call CM_timer_start(0)
  28.                 call walltime (busy1)
  29.      
  30.         integral = 0.0                  !initialization(front-end)
  31. c       calculate slice size (front end):
  32.         slicesize = (b - a) / points
  33.         i = [1:points]                  !array constructor(CM)
  34.         x = a + (i - 0.5)*slicesize     !array expression(CM)
  35.  
  36. c    each processor calculates the partial integral
  37.         call fun(f,x,points)
  38.     partialint = f * slicesize   !inprocessor operation(CM)
  39.         integral = sum(partialint)      !sum reduction function(CM operation
  40.                                         !that ends up with a scalar passed to the front-end)
  41.  
  42.                 call CM_timer_stop(0)
  43.                 call walltime (busy2)
  44.  
  45.                 call CM_timer_print(0)
  46.                 busy1 = busy2 - busy1
  47.         write(6,*) 'MFLOPS = ', points*8/(busy1*10**6) 
  48.         write(6,*) 'Sum = ',integral
  49.         write(6,*) 'Error = ',integral-3.14159265358979323846
  50.  
  51.     return
  52.         end
  53.  
  54.