[Bug libgomp/43706] New: scheduling two threads on one core leads to starvation

2010-04-09 Thread baeuml at kit dot edu
The following code results in starvation if at least two OpenMP threads are
assigned to one core.

#include cstdio

int main()
{
while (true) {
#pragma omp parallel for
for (int ii = 0; ii  1000; ++ii) {
int s = ii;
}
printf(.);
}

return 0;
}

Compiled with
 g++ -fopenmp -save-temps -o test test.cpp

and ran with
 GOMP_CPU_AFFINITY=0 1 2 ./test

on a quad-core (Q9550) system results in veeery slow progress.


However,
 GOMP_CPU_AFFINITY=0 1 2 3 ./test
runs as expected.

This happens also, if cpu affinity is not explicitly given, but some of the
cores are busy with other processes. In this case it also helps to explicitly
assign each thread to one core with GOMP_CPU_AFFINITY=0 1 2 3.

 gcc -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.4
--enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/
--with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap
--with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --program-suffix=-4.4
--enable-linux-futex --without-system-libunwind --with-arch-32=i586
--with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.4.1 [gcc-4_4-branch revision 150839] (SUSE Linux)


-- 
   Summary: scheduling two threads on one core leads to starvation
   Product: gcc
   Version: 4.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libgomp
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: baeuml at kit dot edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43706



[Bug libgomp/43706] scheduling two threads on one core leads to starvation

2010-04-09 Thread baeuml at kit dot edu


--- Comment #1 from baeuml at kit dot edu  2010-04-09 16:22 ---
Created an attachment (id=20348)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20348action=view)
output of -save-temps


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43706



[Bug libgomp/43706] scheduling two threads on one core leads to starvation

2010-04-09 Thread baeuml at kit dot edu


--- Comment #3 from baeuml at kit dot edu  2010-04-09 20:55 ---
 Have you done a profile (using oprofile) to see why this happens.

I've oprofile'd the original program from which this is a stripped down minimal
example.  I did not see anything unusual, but I'm certainly no expert with
oprofile.

Gdb however shows that all 4 threads are waiting in do_wait()
(config/linux/wait.h)

 Really I think GOMP_CPU_AFFINITY should not be used that much as it will cause
 starvation no matter what.

As I said, this happens also without GOMP_CPU_AFFINITY when there is enough
load on the cores.  By using GOMP_CPU_AFFINITY I'm just able to reproduce the
issue reliably with the given minimal example without needing to put load on
the cores.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43706