Page MenuHomec4science

pi_seq.f90
No OneTemporary

File Metadata

Created
Wed, Sep 11, 03:05

pi_seq.f90

! ==========================================================================
! This exercise is taken from the class Parallel Programming Workshop (MPI,
! OpenMP and Advanced Topics) at HLRS given by Rolf Rabenseifner
! ==========================================================================
program pi
implicit none
integer :: myrank, num_threads
integer, parameter :: n = 10000000
double precision :: omp_t1, omp_t2
double precision :: dx, x, sm, lsum, pif
double precision, external :: second,f
integer :: i
! calculate pi = integral [0..1] 4 / (1 + x**2) dx */
omp_t1 = second()
dx = 1. / n
sm = 0.0;
do i = 1, n
x = (1. * i - 0.5) * dx
sm = sm + f(x)
enddo
pif = dx * sm
omp_t2 = second()
print *, 'computed pi =',pif
print *, 'Running time = ', (omp_t2-omp_t1)
end program pi
double precision function f(a)
implicit none
double precision, intent(in) :: a
f = 4. / (1. + (a**2))
end function f

Event Timeline