Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29273 Discussions

OpenMP parallel section not forking from call within a library

jfwieden
Beginner
625 Views
I'm finding that an OMP parallel construct called from a subroutine contained within a library does not fork. However, a call to OMP_GET_MAX_THREADS() returns 4. I.e. > 1. The same snippet of code, called from the main program works properly.

I've posted the routine here. It first prints the maximum number of threads available in a parallel section. Next, within the parallel section, each thread simply reports it's ID. This code allows you to verify that the main thread forked off into several slaves.

Given that I use the same compiler flags for both the library and the main driver program (both Intel Fortran 9.1 projects), what possible reason why OpenMP will not fork from within the library?

Here is the screen output.
From within the main driver program...
nThreadMax = 4
Thread 1 of 4 reporting
Thread 2 of 4 reporting
Thread 3 of 4 reporting
Thread 4 of 4 reporting

And then the output from the subroutine above called from within the library...
nThreadMax = 4
Thread 1 of 1 reporting

Clearly the call to OMP_GET_MAX_THREADS() returns 4 but the parallel section is only being handled by one thread.
0 Kudos
1 Reply
jfwieden
Beginner
625 Views
Quoting - jfwieden
I'm finding that an OMP parallel construct called from a subroutine contained within a library does not fork. However, a call to OMP_GET_MAX_THREADS() returns 4. I.e. > 1. The same snippet of code, called from the main program works properly.

I've posted the routine here. It first prints the maximum number of threads available in a parallel section. Next, within the parallel section, each thread simply reports it's ID. This code allows you to verify that the main thread forked off into several slaves.

Given that I use the same compiler flags for both the library and the main driver program (both Intel Fortran 9.1 projects), what possible reason why OpenMP will not fork from within the library?

Here is the screen output.
From within the main driver program...
nThreadMax = 4
Thread 1 of 4 reporting
Thread 2 of 4 reporting
Thread 3 of 4 reporting
Thread 4 of 4 reporting

And then the output from the subroutine above called from within the library...
nThreadMax = 4
Thread 1 of 1 reporting

Clearly the call to OMP_GET_MAX_THREADS() returns 4 but the parallel section is only being handled by one thread.

Here is the source for that routine. Forgot at paste it in.
!==============================================================================

SUBROUTINE TestSetup()
!==============================================================================
! General setup routine for testing OMP within a library
!==============================================================================
!Declare imports
USE OMP_LIB
IMPLICIT NONE

!Local variables
INTEGER::nThread,nThreadMax
!==============================================================================
nThreadMax = OMP_GET_MAX_THREADS()
WRITE(6,'("nThreadMax = ",I2)') nThreadMax

!$OMP PARALLEL
nThread = OMP_GET_NUM_THREADS()
!$OMP CRITICAL
WRITE(6,'("Thread ",I2," of ",I2," reporting")') OMP_GET_THREAD_NUM()+1,nThread
!$OMP END CRITICAL
!$OMP END PARALLEL

END SUBROUTINE TestSetup

!==============================================================================
0 Kudos
Reply