Hi, I am new to parallel programming and I am trying to get a simple example to prove to myself that it works on my machine (IBM with 8 Intel processors) before I start trying to implement it in larger projects.

I code in Fortran90/95 and I am using openMP v.2.5. The code below estimates the value of pi, and I have added a few extra 'do loops' to try and increase the workload of the main 'do loop' that is being parallelized. *Note that on my system monitor all 8 processor are functioning at ~100% when NUM_THREADS=8, and when I print out the idate(8) the different threads seem to be working at the same time. The problem is that it takes more than twice as long when NUM_THREADS=8 than when NUM_THREADS=1? Any advice would be greatly appreciated.

=========================================

program pi

implicit none

integer, parameter :: itr=100

integer(kind=8), parameter :: n_points=80

integer :: circle_count, i, j, k, kk, isize

real :: pie, r1, r2, x, y, x_sqr, y_sqr, avg_pie

integer, allocatable :: iseed(:)

real, dimension(itr) :: u_temp

real, dimension(n_points):: circle_count_array1

integer :: TID, OMP_GET_THREAD_NUM, idate(8)

open(1,file='results.dat')

!!!Print out Sim start time

call DATE_AND_TIME(VALUES=idate)

print *, "Simulation start date/time = ", idate

do k=1,itr

pie=0

circle_count=0

circle_count_array1=0

!!!Generate a random seed

call random_seed(SIZE=isize) !to ensure a randomized seed, date_and_time intrinsic is used to obtain a seed from the system date

allocate( iseed(isize) )

call random_seed(GET=iseed)

iseed = iseed * (idate(8)-500) ! idate(8) contains millisecond

call random_seed(PUT=iseed)

deallocate(iseed)

!!!Parallelized loop

!$OMP PARALLEL NUM_THREADS(8) PRIVATE(x,x_sqr,y,y_sqr,r1,r2,j,TID)

!$OMP DO

do j=1,n_points

do i=1,n_points

do kk=1,n_points

call random_number(r1)

call random_number(r2)

x = (2.0 * r1) - 1.0

x_sqr = x * x

y = (2.0 * r2) - 1.0

y_sqr = y * y

if ((x_sqr + y_sqr) <= 1.0) then

circle_count_array1(j) = 1

else

circle_count_array1(j) = 0

end if

call DATE_AND_TIME(VALUES=idate)

TID = OMP_GET_THREAD_NUM()

!!!Get thread number and time in milliseconds

!!$OMP CRITICAL

!write(1,*), TID, idate(8)

!!$OMP END CRITICAL

end do

end do

end do

!$OMP END DO

!$OMP END PARALLEL

circle_count = SUM(circle_count_array1)

!Calculate and print to screen value of pi

pie = 4.*circle_count/n_points

u_temp(k) = pie

end do

avg_pie = SUM(u_temp)/itr

print *, "Avg 'pi' = ", avg_pie

!Print out Sim end time

call DATE_AND_TIME(VALUES=idate)

print *, "Simulation end date/time = ", idate

close(1)

end program pi

=========================================