| Table of Contents | Previous Slide | Next Slide |
Software Development in the UNIX Environment
OpenMP
A C example using the Monte Carlo PI calculation example
#pragma omp parallel default(none) \
private(i,x,y,z) shared(count)
#pragma omp for
for ( i=0; i<niter; i++) {
x = (double)rand()/RAND_MAX;
y = (double)rand()/RAND_MAX;
z = x*x+y*y;
if (z<=1) count++;
}
A Fortran example using the Monte Carlo PI Calculation
c$omp parallel default(none)
c$omp&private(i,j,x,y,z,count,niter) shared(pi)
c$omp do
do j= 1,1000
niter = niter+100
count =0
do i=1,niter
x=rand()
y=rand()
z= x*x +y*y
if (z .le. 1) count =count+1
end do
pi(j)= count/niter*4.
write(*,10) niter,pi(j)
10 format('Number of trials is: 'i5,' estimate of pi is:',f8.5)
end do
c$omp end do
c$omp end parallel
end
OpenMP Resources: