openmp slower than serial computation, FORTRAN90

General OpenMP discussion

openmp slower than serial computation, FORTRAN90

Postby javierburgos » Thu Jun 06, 2013 3:48 am

this is a simple loop, i have some global variable, I measured at runtime loop with and without openmp

SUBROUTINE computeMacros(f,rho,u,uSqr,image)
USE simParam, ONLY: xDim, yDim
USE cellConst, ONLY: wall
implicit none

double precision, INTENT(IN):: f(yDim,xDim,0:8)
double precision, INTENT(INOUT):: u(yDim,xDim,0:1), rho(yDim, xDim), uSqr(yDim, xDim)
integer, INTENT(IN):: image(yDim,xDim)
integer:: x,y
double precision:: time3, time4, timeTot1

timeTot1 = 0.0d0
CALL CPU_TIME(time3)
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(y,x)
do x = 1, xDim
do y = 1, yDim
rho(y,x) = f(y,x,0) + f(y,x,1) + f(y,x,2) + f(y,x,3) + f(y,x,4) + f(y,x,5) + f(y,x,6) + f(y,x,7) + f(y,x,8)
u(y,x,0) = (f(y,x,1) - f(y,x,3) + f(y,x,5) - f(y,x,6) - f(y,x,7) + f(y,x,8)) / rho(y,x)
u(y,x,1) = (f(y,x,2) - f(y,x,4) + f(y,x,5) + f(y,x,6) - f(y,x,7) - f(y,x,8)) / rho(y,x)
uSqr(y,x) = u(y,x,0) * u(y,x,0) + u(y,x,1) * u(y,x,1)
end do
end do
!$OMP END PARALLEL DO
CALL CPU_TIME(time4)
timeTot1 = timeTot1 + (time4-time3)
write(*,*) 'total time:', timeTot1, ' seconds'

END SUBROUTINE computeMacros

f = fEq
global V = f(y,x,i) = (1.0d0 - omega) * f(y,x,i) + omega * fEq(y,x,i)
nu = uMax* dble(obstR) / Re
omega = 1.0d0 / (3.0d0*nu+0.5d0) in the other subrutine,

and fEq is other subrutine too


SUBROUTINE computeFeq(fEq,rho,u,uSqr)
USE D2Q9COnst, ONLY: t, v
USE simParam, ONLY: xDim, yDim
implicit none
double precision, INTENT(IN):: rho(yDim,xDim), uSqr(yDim,xDim), u(yDim,xDim,0:1)
double precision, INTENT(INOUT):: fEq(yDim,xDim,0:8)
integer:: i, x, y
double precision:: uxy

do i = 0, 8
do x = 1, xDim
do y = 1, yDim
uxy = u(y,x,0) * v(i,0) + u(y,x,1) * v(i,1)
fEq(y,x,i) = t(i) * rho(y,x) * (1.0d0 + 3.0d0 * uxy + 4.5d0 * uxy * uxy - 1.5d0 * uSqr(y,x))
end do
end do
end do


END SUBROUTINE computeFeq

time in serie =9.6E-2 seconds
time with openmp = 0.140 seconds

what is wrong ??
javierburgos
 
Posts: 2
Joined: Wed Jun 05, 2013 7:52 am

Re: openmp slower than serial computation, FORTRAN90

Postby MarkB » Thu Jun 06, 2013 4:32 am

I think you are measuring CPU time, which will be accumulated across all threads, and not wall clock time: you should try using omp_get_wtine() instead of CPU_TIME().
MarkB
 
Posts: 427
Joined: Thu Jan 08, 2009 10:12 am

Re: openmp slower than serial computation, FORTRAN90

Postby zerothi » Fri Jun 07, 2013 12:56 pm

You really need to reconstruct your program if f(:,:,:) is always used like this. FORTRAN is column major, so please reconstruct your f to this:
Code: Select all
double precision, INTENT(IN):: f(0:8,yDim,xDim)

this should give you immediate speed improvements (in both versions).
zerothi
 
Posts: 3
Joined: Fri Jun 07, 2013 12:25 pm


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 9 guests

cron