0

My (Fortran) code is very simple. All it does is filling up a large array, that depends on five (independent!) variables. Here is a brief example

 do i = 1, imax
   do j = 1, jmax
     do k = 1, kmax

    array(i,j,k) = ! some function of i,j,k

    end do
   end do
 end do

I would to use different threads to fill the values of array in a faster way.

I thought the simplest way to achieve that would be to enclose the loop in these commands

!$OMP PARALLEL DO

!$OMP PARALLEL END

However, if I do this I get completely different results from the serial case. I apologize if the question is too simple, but I couldn't really find a proper example to help solve my problem. Can you recommend a solution or provide an example?

3
  • 7
    Be more specific about the rhs of the assignment statement. Post a minimal example which exhibits the mis-behaviour that concerns you. Commented Nov 10, 2014 at 13:43
  • 5
    As well a what Mark says I have to ask if the loops are really ordered as you say above? If so this is totally the wrong way round for Fortran, it's just about as memory subsystem unfriendly as you can get, and you almost certainly get at least as much speed up from fixing that as from using OpenMP Commented Nov 10, 2014 at 15:27
  • @IanBush: agree on the need to fix loop ordering, but not that you get at least as much speed up, that depends a lot on what the RHS looks like. Commented Nov 10, 2014 at 15:51

1 Answer 1

0

I don't exatly know what is happening, but it could be a race condition or just bad declaration of the directives. Try this and see if it works

!replace ... with variables that are constants as in shared(a,b,c)
!$omp parallel do default(private) shared(...) 
do i=1,imax
    j=1,jmax
        k=1,kmax
            array(i,j,k) = ! some function of i,j,k

        end do
     end do
 end do
 !$omp end parallel do
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.