Archives

- Beowulf
- Beowulf Announce
- Scyld-users
- Beowulf on Debian

# [Beowulf] OpenMP on AMD dual core processors

Many of your questions may have already been answered in earlier discussions or in the FAQ. The search results page will indicate current discussions as well as past list serves, articles, and papers.

Search

Nathan Moore ntmoore at gmail.com
Thu Nov 20 19:52:47 PST 2008

```Hi All,

I'm getting to the end of a semester of computational physics at my
institution, and thought it would be fin to close the semester with a
discussion of parallel programming.  Initially, I was simply planning to
discuss MPI, but while reading through the gfortran man page I realized that
gcc now supports OpenMP directives.

Given that the machines my students are using are all dual core, I started
working on a simple example that I hoped would show a nice speedup from the
"easy" library.

The specific problem I'm working on is a 2-d solution to the laplace
equation (electrostatics).  The bulk of the computation is a recursion
relation, applied to elements of a 2-d array, according to the following
snippet.

Of course, by now I should know that "simple" never really is.  When I
compile with gfortran and run with 1 or 2 cores (ie, OMP_NUM_THREADS=2,
export OMP_NUM_THREADS) there is basically no difference in execution time.

Any suggestions?  I figured that this would be a simple example to
parallelize.  Is there a better example for OpenMP parallelization?  Also,
is there something obvious I'm missing in the example below?

Nathan Moore

integer,parameter::Nx=1000
integer,parameter::Ny=1000
real*8 v(Nx,Ny)
integer boundary(Nx,Ny)

v_cloud = -1.0e-4
v_ground = 0.d0

convergence_v = dabs(v_ground-v_cloud)/(1.d0*Ny*Ny)

! initialize the the boundary conditions
do i=1,Nx
do j=1,Ny
v_y = v_ground + (v_cloud-v_ground)*(j*dy/Ly)
boundary(i,j)=0
v(i,j) = v_y
! we need to ensure that the edges of the domain are held as
boundary
if(i.eq.0 .or. i.eq.Nx .or. j.eq.0 .or. j.eq.Ny) then
boundary(i,j)=1
endif
end do
end do

10 converged = 1
!\$OMP PARALLEL
!\$OMP DO
do i=1,Nx
do j=1,Ny
if(boundary(i,j).eq.0) then
old_v = v(i,j)
v(i,j) =
0.25*(v(i-1,j)+v(i+1,j)+v(i,j+1)+v(i,j-1))
dv = dabs(old_v-v(i,j))
if(dv.gt.convergence_v) then
converged = 0
endif
endif
end do
end do
!\$OMP ENDDO
!\$OMP END PARALLEL
if(converged.eq.0) then
goto 10
endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.scyld.com/pipermail/beowulf/attachments/20081120/978f6317/attachment.html
```