Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92095486
pi_reduction.f90
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Nov 17, 07:45
Size
1 KB
Mime Type
text/x-c
Expires
Tue, Nov 19, 07:45 (2 d)
Engine
blob
Format
Raw Data
Handle
22375578
Attached To
rSCINTROPAR Introduction to parallelism
pi_reduction.f90
View Options
! ==========================================================================
! This exercise is taken from the class Parallel Programming Workshop (MPI,
! OpenMP and Advanced Topics) at HLRS given by Rolf Rabenseifner
! ==========================================================================
program pi_reduction
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
!$ double precision, external :: omp_get_wtime
integer :: i
! calculate pi = integral [0..1] 4 / (1 + x**2) dx */
omp_t1 = second()
!$ omp_t1 = omp_get_wtime()
dx = 1. / n
sm = 0.0;
!$OMP parallel do private(i) reduction(+:sm)
do i = 1, n
x = (1. * i - 0.5) * dx
sm = sm + f(x)
enddo
!$OMP end parallel do
pif = dx * sm
omp_t2 = second()
!$ omp_t2 = omp_get_wtime()
print *, 'computed pi =',pif
print *, 'Running time = ', (omp_t2-omp_t1)
end program pi_reduction
double precision function f(a)
implicit none
double precision, intent(in) :: a
f = 4. / (1. + (a**2))
end function f
Event Timeline
Log In to Comment