am I misunderstanding?

General OpenMP discussion

am I misunderstanding?

Postby nucci6 » Fri Sep 26, 2008 8:25 am

This is a tale of 2 Fortran 90 codes.

One looks like this:

integer omp_get_thread_num

integer a(8)
integer i

a = -99

!$OMP PARALLEL &
!$OMP shared(a)

a(omp_get_thread_num()+1) = omp_get_thread_num()

!$OMP END PARALLEL

write(6,*) (a(i), i=1,8)

end

this returns results I would expect:

$ ./a.out
0 1 2 3 4 5
6 7

this code, on the other hand:

! test obtaining omp thread number
!
integer i
integer iam
integer iam_arr(8)
iam_arr = -99
iam = -99

!$omp parallel private(iam) shared(iam_arr)

iam=omp_get_thread_num()
iam_arr(iam+1) = iam

!$omp end parallel

write(6,*) 'iam: ', (iam_arr(i), i=1,8)

end

has different output:

[nucci@lionxj OpenMP]$ ./a.out

iam: 0 -99 -99 -99 -99 -99
-99 -99

SInce 'iam' is declared as a private variable, should it not pick up the correct value from omp_get_thread_num() and store it in the proper location of iam_arr? If I try to print out 'iam' in the parallel region it always returns 0. Am I misunderstanding something here? I tried this with a couple of different compilers (ifort, pgi) and the results are the same.

Thanks
nucci6
 
Posts: 1
Joined: Fri Sep 26, 2008 8:13 am

Re: am I misunderstanding?

Postby ejd » Fri Sep 26, 2008 2:33 pm

There is actually a very large difference between your two programs. In the first, you have a declaration for omp_get_thread_num and in the second you don't. Fortran default rules are that variables that start with the letters i through n are integer and everything else is real. When I run your second program I get an arithmetic exception. Add the declaration for omp_get_thread_num or use (or include - depending on what is provided by the implementation) omp_lib and the second program will work fine.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 16 guests