program main c*********************************************************************72 c cc MAIN is the main program for QUAD. c c Discussion: c c QUAD is a FORTRAN77 program to estimate the integral of c f = 50.0 / ( pi * ( 2500.0 * x(i) * x(i) + 1.0 ) ) c from 0 to 10. c c If you modify the program in 4 places, it should run correctly c under OpenMP. c c If you can do that, then compare the execution time when you c use 1, 2, 4 or 8 threads. c c Licensing: c c This code is distributed under the GNU LGPL license. c c Modified: c c 03 September 2013 c c Author: c c John Burkardt c c c CHANGE 1) Activate the following INCLUDE statement. c c include 'omp_lib.h' double precision a double precision b double precision error double precision exact integer i integer n double precision pi double precision total double precision wtime double precision x(1000000) a = 0.0 b = 10.0 exact = 0.49936338107645674464D+00 n = 1000000 pi = 3.141592653589793D+00 wtime = 0.0D+00 write ( *, * ) ' ' write ( *, * ) 'QUAD:' write ( *, * ) ' FORTRAN77 version' write ( *, * ) ' ' write ( *, * ) ' Estimate the integral of f(x) from A to B.' write ( *, * ) ' f(x) = 50 / (pi * ( 2500 * x * x + 1 ) ).' write ( *, * ) ' A = ', a write ( *, * ) ' B = ', b write ( *, * ) ' Exact integral is 0.49936338107645674464...' c c Load the array X with evenly spaced values between A and B. c do i = 1, n x(i) = ( dble ( n - i ) * a & + dble ( i - 1 ) * b ) & / dble ( n - 1 ) end do c c Evaluate F at each node, sum and average. c c c CHANGE 2) Use the OpenMP timer here to initialize WTIME. c c wtime = ??? c total = 0.0D+00 c c CHANGE 3) Fill in these two OpenMP directives here c c$omp parallel private ( ??? ) shared ( ??? ) c$omp do ??? do i = 1, n total = total + 50.0D+00 & / ( pi * ( 2500.0D+00 * x(i) * x(i) + 1.0D+00 ) ) end do c c CHANGE 3.1) Insert "closing" OpenMP directives after the loop c c$omp end do c$omp end parallel c total = ( b - a ) * total / dble ( n ) c c CHANGE 4) Call the OpenMP timer here to update WTIME. c c wtime = ??? c c Print quadrature estimate, error, time c error = abs ( total - exact ) write ( *, * ) ' ' write ( *, * ) ' Estimate = ', total write ( *, * ) ' Error = ', error write ( *, * ) ' Wallclock time = ', wtime stop end function f ( x ) double precision f double precision pi double precision x pi = 3.141592653589793D+00 c c Write the formula for the function here. c f = 50.0 / (pi * ( 2500.0 * x * x + 1.0 ) ) return end