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