Openmp Question

General OpenMP discussion

Openmp Question

Postby stevo » Mon Aug 04, 2008 10:16 pm

Hi all.

I am new to the world of parallel computing and I am trying to parallise a wave model but I have run into a few difficulties that I have been unable to overcome after looking through a bunch of info on Openmp. The model has been written in fortan and has the general format shown below. The sections in brackets are explained below and have been included to test whether the code works, it doesn't.


do i=1,ns

do j=2,wd
dependent calcs ie h(j) = h(j-1)

A number of functions are called

do j=1,wd
independent calcs

A few more functions are called

I want to parallise the section of the code where the independent calcs are done. I have tried using !$OMP ORDERED to achieve this but the code just takes longer to run that it does with 1 cpu. As a check I attempted to order the whole model (using the bracketed constructs) but this also took longer??? I thought that the ORDERED construct would operate as though only 1 cpu was used with calcs done in the given order. My idea was to use this method to isolate the sections of the code that contained the functions and dependent calcs leaving the paralliseable section. I am not sure if there is a better way to do this but what really concerns me is that when the entire loop is ordered the code takes significantly longer to run. I am new to this so I imagine I am missing something, I just don't know what it is.

I was under the impression that the ordered construct could be placed around a block of code. Are there specific things that this block can/cannot contain. Any advice would be greatly appreciated.


Re: Openmp Question

Postby ejd » Tue Aug 05, 2008 6:02 am

The ordered construct "sequentializes and orders the code within an ordered region while allowing code outside the region to run in parallel". The problem is, that the only code you have shown outside the ordered region is the workshare do. This means that each thread is going to get some chunk of iterations to do of the workshare and it is going to order the chunks. This is exactly what the sequential version does - but with less overhead - so your program is going to take longer running parallel than serially.

Ordered regions are of use when you have a lot of work that can be done outside of the ordered region. For example:
Code: Select all
!$omp do schedule(static, 1)
do i = 1, ns
  ... possibly a lot of work here
  !$omp ordered
    ... some small amount of work here
  !$omp end ordered
  ... possibly a lot of work here
!$omp end do

You really need to have either a lot of work that is independent of the ordered region either before or after the ordered region to get any benefit in using it. You will also note that I used a schedule clause with a chunk size of 1. If you don't do this, then the thread that is going to do the next iteration is the same one doing the current iteration and you won't see much (if any) speedup either. That is because the large amount of work that can be done in parallel isn't going to be done because the thread is busy doing the current work.
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 2 guests