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?
it is obvious that the creation of the thread overheads will largely decelerate this speedThis is not at all obvious and really depends on what you compute. If you solve a simple ODE than yes. If you solve a PDE with millions of degrees of freedom, you can probably neglect it, as I do. The threads are not created each time, just synchronized and re-used.