omp_get_num_threads returns 0 for all threads

General OpenMP discussion

omp_get_num_threads returns 0 for all threads

Postby crc_dwong » Tue Aug 28, 2012 6:23 am

Hi,

I ran the following code on one machine and it works fine. However, when I moved the code to another machine and omp_get_num_threads returns 0 for all threads. I wonder why. They both were compiled with ifort 11. Your insight will be appreciated.

Regards,
David


program test

USE omp_lib
IMPLICIT NONE
include 'mpif.h'

integer :: my_tid, stat, mype, error, nprocs

CALL MPI_INIT( error )
CALL MPI_COMM_SIZE( MPI_COMM_WORLD, NPROCS, error )
CALL MPI_COMM_RANK( MPI_COMM_WORLD, MYPE, error )

!$OMP PARALLEL
!$ $ PRIVATE ( MY_TID )

MY_TID = OMP_GET_THREAD_NUM() + 1

print *, ' ==d== tid ', mype, my_tid

!$OMP END PARALLEL ! End OpenMP parallel section

call mpi_finalize (error)

end program test
crc_dwong
 
Posts: 5
Joined: Tue Apr 19, 2011 9:52 am

Re: omp_get_num_threads returns 0 for all threads

Postby MarkB » Tue Aug 28, 2012 7:03 am

Hi David,

Your code as posted doesn't compile under PGI or GNU: the line

!$ $ PRIVATE ( MY_TID )

is broken!

Is this a typo or does ifort accept it?

Mark.
MarkB
 
Posts: 456
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: omp_get_num_threads returns 0 for all threads

Postby crc_dwong » Tue Aug 28, 2012 8:00 am

Hi Mark,

I compiled the code in a fixed form. I guess when I cut and paste the code, all the blank space has been collapsed (I didn't realized when I post it). Here is the code again with proper spacing.

Regards,
David

program test

USE omp_lib
IMPLICIT NONE
include 'mpif.h'

integer :: my_tid, stat, mype, error, nprocs

CALL MPI_INIT( error )
CALL MPI_COMM_SIZE( MPI_COMM_WORLD, NPROCS, error )
CALL MPI_COMM_RANK( MPI_COMM_WORLD, MYPE, error )

!$OMP PARALLEL
!$ $ PRIVATE ( MY_TID )

MY_TID = OMP_GET_THREAD_NUM() + 1

print *, ' ==d== tid ', mype, my_tid

!$OMP END PARALLEL ! End OpenMP parallel section

call mpi_finalize (error)

end program test
crc_dwong
 
Posts: 5
Joined: Tue Apr 19, 2011 9:52 am

Re: omp_get_num_threads returns 0 for all threads

Postby MarkB » Wed Aug 29, 2012 2:21 am

Hi David,

That looks just the same, but in any case the correct syntax for a fixed format directive continuation line should be

Code: Select all
!$OMP$ PRIVATE ( MY_TID )


It is possible that the Intel compiler is ignoring the private clause, which could result in the behaviour you report (because MY_TID would then be shared by default).

Hope that helps,
Mark.
MarkB
 
Posts: 456
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: omp_get_num_threads returns 0 for all threads

Postby crc_dwong » Wed Aug 29, 2012 5:34 am

Hi Mark,

Thanks for pointing out the continuation format. Apparently, intel and pgf accept different format and I guess I will use !$OMP$ so both compilers will accept. The troubling issue is I compiled the same code with intel v11 on two different machines and one works (machine A) and one does not (machine B). On machine B, I used !$OMP$ at the beginning of the continuation line but it still did not work. I even put everything into one line to eliminate the continuation line issue and it still returns 0s. I wonder there is anything to do with the compiler installation (they were not installed by the same person).

Regards,
David
crc_dwong
 
Posts: 5
Joined: Tue Apr 19, 2011 9:52 am

Re: omp_get_num_threads returns 0 for all threads

Postby MarkB » Wed Aug 29, 2012 6:57 am

crc_dwong wrote:I even put everything into one line to eliminate the continuation line issue and it still returns 0s.


How are you setting the number of threads, and what does OMP_GET_NUM_THREADS() return inside the parallel region?
MarkB
 
Posts: 456
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: omp_get_num_threads returns 0 for all threads

Postby crc_dwong » Thu Aug 30, 2012 8:04 am

Hi Mark,

I have found the problem. Somehow the gcc openmp lib is used instead of intel. Once I use intel openmp lib, things are working.

Regards,
David
crc_dwong
 
Posts: 5
Joined: Tue Apr 19, 2011 9:52 am

Re: omp_get_num_threads returns 0 for all threads

Postby MarkB » Thu Aug 30, 2012 8:40 am

Hi David,

Great, glad you managed to solve it!

Mark.
MarkB
 
Posts: 456
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: Exabot [Bot] and 11 guests

cron