Bug 32468 - number of threads in a parallel region depends on number of SECTIONs and MAX_THREADS
Summary: number of threads in a parallel region depends on number of SECTIONs and MAX_...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgomp (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords: openmp
Depends on:
Blocks:
 
Reported: 2007-06-22 19:56 UTC by Bill Long
Modified: 2007-07-02 19:28 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.2.1 4.3.0
Last reconfirmed: 2007-06-22 21:54:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Long 2007-06-22 19:56:12 UTC
Description:
This test case exhibits the problem that the presence of a SECTIONS directive
with only one SECTION inside of a PARALLEL region causes only one thread to be
created when omp_set_num_threads was previously called with 4 threads.  If
the directives internal to this PARALLEL region are commented out, 4 threads
are created and the program produces expected output.  The compiler used
was GNU gfortran.  The test case works as expected when compiled with PGI.

> gfortran -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../xt-gcc-4.2.0/configure --prefix=/opt/gcc/4.2.0/snos --disable-nls --libdir=/opt/gcc/4.2.0/snos/lib --enable-languages=c,c++,fortran --with-gxx-include-dir=/opt/gcc/4.2.0/snos/include/g++ --with-slibdir=/opt/gcc/4.2.0/snos/lib --with-system-zlib --enable-shared --enable-__cxa_atexit x86_64-suse-linux
Thread model: posix
gcc version 4.2.0 20070514 (rpm:4)


> cat bug2831.f90
! Derived from OpenMP test omp1/F2_1_1_2_1c.f90
      use omp_lib
      implicit none
      integer, parameter :: NT = 4
      integer :: nth

!$    call omp_set_dynamic(.false.)
!$    call omp_set_num_threads(NT)
!$omp parallel default(none) shared(nth)
      print *, omp_get_thread_num(), omp_get_num_threads()
!$omp sections
!$omp section
      nth=omp_get_num_threads()
!$omp endsections
!$omp endparallel

      print *, 'nth=',nth,'  NT=',NT
      END

> diff bug2831.f90 bug2831a.f90
11,12d10
< !$omp sections
< !$omp section
14d11
< !$omp endsections

Incorrect output is produced:

> ftn -O0 -fopenmp -o x bug2831.f90
/opt/xt-pe/2.1/bin/snos64/ftn: INFO: linux target is being used
> aprun -n 1 ./x
           0           1
 nth=           1   NT=           4
Application 217361 resources: utime 0, stime 0

Correct output from program with sections/section directives removed:

> ftn -O0 -fopenmp -o xa bug2831a.f90
/opt/xt-pe/2.1/bin/snos64/ftn: INFO: linux target is being used
> aprun -n 1 ./xa
           0           4
           1           4
           3           4
           2           4
 nth=           4   NT=           4
Application 217362 resources: utime 0, stime 0


------
Note: ftn is an alias for:

/opt/gcc/4.2.0/bin/../snos/bin/gfortran -static -v -I/opt/xt-mpt/2.1/mpich2-64/GP/include -I/opt/xt-mpt/2.1/mpich2-64/GP/include -L/opt/xt-mpt/2.1/mpich2-64/GP/lib -I/opt/acml/3.6.1/gnu64/include -I/opt/xt-libsci/10.1.0/gnu/snos64/include -I/opt/xt-libsci/10.1.0/gnu/snos64/include/superlu -I/opt/xt-mpt/2.1/sma/P/include -L/opt/acml/3.6.1/gnu64/lib -L/opt/xt-libsci/10.1.0/gnu/snos64/lib -L/opt/xt-mpt/2.1/sma/P/lib -lmpichf90 -lsci -lacml -lsma -lmpichf90 -lmpich -lrt -D__CRAYXT_COMPUTE_LINUX_TARGET -D__TARGET_LINUX__ -fno-second-underscore -I/notbackedup/users/rsrel/rs64.DEV.070604.Mon/install/include -I/opt/xt-catamount/2.1/catamount/linux/include -I/opt/xt-service/2.1/include -L/notbackedup/users/rsrel/rs64.DEV.070604.Mon/install/lib/snos64 -L/opt/xt-pe/2.1/cnos/linux/64/lib -L/opt/xt-mpt/2.1/lib/snos64 -L/opt/xt-service/2.1/lib/snos64 -Wl,--start -lpct -lalpslli -lalpsutil -lportals -lpthread -Wl,--end -lgfortranbegin -lgfortran -lm
Comment 1 Daniel Franke 2007-06-22 21:37:31 UTC
Toying with the example shows that the number of threads in the parallel region always equals the minimum of the number of SECTIONs or the MAX_NUM_THREADS. I.e. adding another SECTION will create two threads, having 5 sections will result in 4 threads as NT==4. 

This is true for both, 4.2 and latest svn (20070622).

Adding Jakub as CC.
Comment 2 Jakub Jelinek 2007-06-22 21:54:00 UTC
There are several issues, will fix them on Monday.
Comment 4 Jakub Jelinek 2007-07-02 19:19:38 UTC
Subject: Bug 32468

Author: jakub
Date: Mon Jul  2 19:19:28 2007
New Revision: 126224

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126224
Log:
	PR libgomp/32468
	* sections.c (GOMP_parallel_sections_start): Only decrease
	number of threads to COUNT if dyn_var is true.
	* testsuite/libgomp.c/pr32468.c: New test.

Added:
    trunk/libgomp/testsuite/libgomp.c/pr32468.c
Modified:
    trunk/libgomp/ChangeLog
    trunk/libgomp/sections.c

Comment 5 Jakub Jelinek 2007-07-02 19:22:58 UTC
Subject: Bug 32468

Author: jakub
Date: Mon Jul  2 19:22:47 2007
New Revision: 126226

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126226
Log:
	PR libgomp/32468
	* omp-low.c (check_combined_parallel): New function.
	(lower_omp_parallel): Call it via walk_stmts, set
	OMP_PARALLEL_COMBINED if appropriate.
	(determine_parallel_type): If OMP_FOR resp. OMP_SECTIONS
	isn't the only statement in WS_ENTRY_BB or OMP_RETURN
	the only one in PAR_EXIT_BB and not OMP_PARALLEL_COMBINED,
	don't consider it as combined parallel.

	* gcc.dg/gomp/pr32468-1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/gomp/pr32468-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/omp-low.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 Jakub Jelinek 2007-07-02 19:26:36 UTC
Subject: Bug 32468

Author: jakub
Date: Mon Jul  2 19:26:25 2007
New Revision: 126227

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126227
Log:
	PR libgomp/32468
	* sections.c (GOMP_parallel_sections_start): Only decrease
	number of threads to COUNT if dyn_var is true.
	* testsuite/libgomp.c/pr32468.c: New test.

Added:
    branches/gcc-4_2-branch/libgomp/testsuite/libgomp.c/pr32468.c
Modified:
    branches/gcc-4_2-branch/libgomp/ChangeLog
    branches/gcc-4_2-branch/libgomp/sections.c

Comment 7 Jakub Jelinek 2007-07-02 19:27:38 UTC
Subject: Bug 32468

Author: jakub
Date: Mon Jul  2 19:27:28 2007
New Revision: 126228

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126228
Log:
	PR libgomp/32468
	* omp-low.c (check_combined_parallel): New function.
	(lower_omp_parallel): Call it via walk_stmts, set
	OMP_PARALLEL_COMBINED if appropriate.
	(determine_parallel_type): If OMP_FOR resp. OMP_SECTIONS
	isn't the only statement in WS_ENTRY_BB or OMP_RETURN
	the only one in PAR_EXIT_BB and not OMP_PARALLEL_COMBINED,
	don't consider it as combined parallel.

	* gcc.dg/gomp/pr32468-1.c: New test.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/gomp/pr32468-1.c
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/omp-low.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 8 Jakub Jelinek 2007-07-02 19:28:38 UTC
Fixed in SVN.