Hi All,<br><br>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.  <br>
<br>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.  <br><br>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.<br>
<br>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.  <br>
<br>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?  <br><br>Nathan Moore<br>
<div style="margin-left: 40px;"><br>integer,parameter::Nx=1000<br>integer,parameter::Ny=1000<br>real*8 v(Nx,Ny)<br>integer boundary(Nx,Ny)<br><br>v_cloud = -1.0e-4<br>v_ground = 0.d0<br><br>convergence_v = dabs(v_ground-v_cloud)/(1.d0*Ny*Ny)<br>
<br>! initialize the the boundary conditions<br>do i=1,Nx<br>        do j=1,Ny<br>                v_y = v_ground + (v_cloud-v_ground)*(j*dy/Ly)<br>                boundary(i,j)=0<br>                v(i,j) = v_y<br>                ! we need to ensure that the edges of the domain are held as boundary<br>
                if(i.eq.0 .or. i.eq.Nx .or. j.eq.0 .or. j.eq.Ny) then<br>                        boundary(i,j)=1<br>                endif<br>        end do<br>end do<br><br>10 converged = 1<br>!$OMP PARALLEL<br>!$OMP DO<br>
        do i=1,Nx<br>                do j=1,Ny<br>                        if(boundary(i,j).eq.0) then<br>                                old_v = v(i,j)<br>                                v(i,j) = 0.25*(v(i-1,j)+v(i+1,j)+v(i,j+1)+v(i,j-1))<br>
                                dv = dabs(old_v-v(i,j))<br>                                if(dv.gt.convergence_v) then<br>                                        converged = 0<br>                                endif<br>
                        endif<br>                end do<br>        end do<br>!$OMP ENDDO<br>!$OMP END PARALLEL <br>if(converged.eq.0) then<br>        goto 10<br>endif<br><br></div><br>