Use OpenMP section parallel in a time-dependent do loop

Use OpenMP section parallel in a time-dependent do loop

I have a quick question regarding the OpenMP. Usually one can do a section parallel like this (written in fortran, and has two sections):

!$OMP PARALLEL SECTIONS
!$OMP SECTION
< Fortran code block A>
!$OMP SECTION
< Fortran code block B>
!$OMP END SECTIONS

Now what I really want to run fortran code block A and B within a do loop, which itself should not be parallelized, because this do-loop is a time-dependent loop that every new step depend on previous step’s results. And before the parallel section, I need to run a serial code (let's call it block C). Now both block A, B, C are function of do loop variable t. Then naively one might propose such code by simply embedded this parallel within a do loop:

do t=1:tmax
    < Fortran serial code block C>
    !$OMP PARALLEL SECTIONS
    !$OMP SECTION
    < Fortran code block A>
    !$OMP SECTION
    < Fortran code block B>
    !$OMP END SECTIONS
end do

However, it is obvious that the creation of the thread overheads will largely decelerate this speed, which even possibly make it slower than a standard serial code. Therefore, one might come up with smarter idea to solve this. 

I was wondering whether you can help me on giving some hints on how to do this. What's the best approach (fastest computation) on this? Thanks a lot for your help! 

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You are asking general OpenMP question on a specific forum dedicated to open source runtime library. You could get more replies on some general forum, like http://openmp.org/forum/.

Anyway, you can move parallel out of the loop, like:

!$omp parallel
  do t = 1,tmax
    !$omp single
      <code C>
    !$omp end single
    !$omp sections
      <code A>
    !$omp section
      <code B>
    !$omp end sections
  enddo
!$omp end parallel

Regards,
Andrey

Leave a Comment

Please sign in to add a comment. Not a member? Join today