CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

OpenMP

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 28, 2011, 12:52
Default OpenMP
  #1
maz
New Member
 
Join Date: Sep 2011
Posts: 2
Rep Power: 0
maz is on a distinguished road
Hi,

Here is an OpenMP implementation of a Laplace solver (a parallel Fortran code). I can get a good speedup on up to 4 processors, but it does not improve when I use more processors.
Could you please let me know how I can get a better speedup by using more processors?

program lpomp
integer imax,jmax,im1,im2,jm1,jm2,it,itmax
parameter (imax=4001,jmax=4001)
parameter (im1=imax-1,im2=imax-2,jm1=jmax-1,jm2=jmax-2)
parameter (itmax=200)
real*8 u(imax,jmax),du(imax,jmax),umax,dumax,tol
parameter (umax=10.0,tol=1.0e-6)
call omp_set_num_threads(2)
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i,j)
!$OMP DO
do j=1,jmax
do i=1,imax-1
u(i,j)=0.0
du(i,j)=0.0
enddo
u(imax,j)=umax
enddo
!$OMP END DO
!$OMP END PARALLEL
it=1
dumax=1.0
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i,j)
! Main computation loop
do it=1,itmax
dumax=0.0
!$OMP DO REDUCTION (max:dumax)
do j=2,jm1
do i=2,im1
du(i,j)=0.25*(u(i-1,j)+u(i+1,j)+u(i,j-1)+u(i,j+1))-u(i,j)
dumax=max(dumax,abs(du(i,j)))
enddo
enddo
!$OMP END DO
!$OMP DO
do j=2,jm1
do i=2,im1
u(i,j)=u(i,j)+du(i,j)
enddo
enddo
!$OMP END DO
enddo
!$OMP END PARALLEL
stop
end

Compile: ifort -openmp -parallel Laplace.for

Thanks!
maz is offline   Reply With Quote

Old   September 30, 2011, 17:58
Default
  #2
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 20
DoHander is on a distinguished road
Comment (or erase) this line:

call omp_set_num_threads(2)

recompile your code and let me know if you see any improvement.
You could also try to enable all optimizations by using for compilation:

ifort -O3 -openmp -parallel Laplace.for

Do
DoHander is offline   Reply With Quote

Old   September 30, 2011, 19:46
Default
  #3
maz
New Member
 
Join Date: Sep 2011
Posts: 2
Rep Power: 0
maz is on a distinguished road
Hi,
I commented the line, but did not see any improvement.
Thanks!
maz is offline   Reply With Quote

Old   September 30, 2011, 21:05
Default
  #4
New Member
 
G.Y.Liang
Join Date: Jan 2011
Posts: 2
Rep Power: 0
G.Y.Liang is on a distinguished road
I can get a good speedup on up to 4 processors, but it does not improve when I use more processors.

Usually I use ifort -fast /Qopenmp filename.f90. I don't know why ifort -fast -openmp cann't be used on my computer(Windows serve OS)

For fixed grids, of course, the performance will be slow down if you use more processors. You can fix you processors first, then increase grids to test the speedup.
G.Y.Liang is offline   Reply With Quote

Old   September 30, 2011, 21:54
Default
  #5
Senior Member
 
Cean
Join Date: Feb 2010
Posts: 128
Rep Power: 16
shirazbj is on a distinguished road
I can compile it with:

gfortran -fopenmp laplace.f90

but when I run it, there is error. Don't kow why?

Thx
shirazbj is offline   Reply With Quote

Old   May 3, 2013, 02:00
Default
  #6
Member
 
Ravindra Shende
Join Date: Feb 2011
Location: Pune, India
Posts: 45
Rep Power: 15
Ravindra Shende is on a distinguished road
Why are you using du(i,j) while you can directly do u(i,j) = 0.25*(u(i-,j)+u(i+1,j)+u(i,j-1)+u(i,j+1)). This will increase the speed of serial code itself.
Ravindra Shende is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to parallelize this fortran code by openmp ronac Main CFD Forum 1 May 11, 2016 03:12
OpenMP in Junction Box Routine Hannes_Kiel CFX 10 September 21, 2010 14:51
About the OpenMP jinwon park Main CFD Forum 5 August 28, 2007 06:47
OpenMP and fortran John Deas Main CFD Forum 0 May 17, 2007 17:53
Parallel computing and OpenMP ganesh Main CFD Forum 7 October 27, 2006 11:15


All times are GMT -4. The time now is 22:03.