[Bug libgomp/126370] New: Reuse threads with same affinity

"avieira at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126370

            Bug ID: 126370
           Summary: Reuse threads with same affinity
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
          Assignee: unassigned at gcc dot gnu.org
          Reporter: avieira at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

Created attachment 65115
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65115&action=edit
reproducer

First off let me start saying I do not think this is a bug. The behavior
libgomp exhibits seems to be entirely compliant with the standard, it just
happens to differ from the LLVM and Intel implementation in a way that some
users believe to be undesirable.

The attached test.cpp case creates N threads (based on the number of cpus
available), then halves them and then sets them back to N. The N or half N here
is not extremely relevant as long as N > 4, the larger it is, the more likely
it is to show the result, in my case N = 16.

The behaviour we are trying to show here is that with libgomp the threads
between N and N/2, keep their affinity when using OMP_PROC_BIND, but they
change their thread ID and gettid. The thread ID's seem to be re-used between
those, and shuffled around, the gettid's are all higher. Whereas for libgomp
they stay the same.

using gomp:
g++ test.cpp -g -std=c++17 -O3 -fstrict-aliasing -xc++ -fopenmp -ffast-math
-lnuma -lgomp -pthread -o gcc_gomp

using llvm omp:
g++ -g -std=c++20 -O3 -fstrict-aliasing -xc++ -fopenmp -ffast-math -c test.cpp
-I /usr/lib/llvm-14/include/
g++ test.o -lnuma -pthread -lomp -L /usr/lib/llvm-14/lib -o gcc_llvmomp 


and then:
OMP_PROC_BIND=true ./gcc_gomp

...
thread 0: 281474842439712, gettid: 41819--> same thread id  --> same gettid
thread 1: 281474836918368, gettid: 41820--> same thread id  --> same gettid
thread 2: 281474828464224, gettid: 41821--> same thread id  --> same gettid
thread 3: 281474820010080, gettid: 41822--> same thread id  --> same gettid
thread 4: 281474811555936, gettid: 41823--> same thread id  --> same gettid
thread 5: 281474803101792, gettid: 41824--> same thread id  --> same gettid
thread 6: 281474794647648, gettid: 41825--> same thread id  --> same gettid
thread 7: 281474786193504, gettid: 41826--> same thread id  --> same gettid
thread 8: 281474769285216, gettid: 41835--> different thread id to:
281474777739360  --> different gettid to: 41827
thread 9: 281474752376928, gettid: 41836--> different thread id to:
281474769285216  --> different gettid to: 41828
thread 10: 281474735468640, gettid: 41837--> different thread id to:
281474760831072  --> different gettid to: 41829
thread 11: 281474727014496, gettid: 41838--> different thread id to:
281474752376928  --> different gettid to: 41830
thread 12: 281474760831072, gettid: 41839--> different thread id to:
281474743922784  --> different gettid to: 41831
thread 13: 281474777739360, gettid: 41840--> different thread id to:
281474735468640  --> different gettid to: 41832
thread 14: 281474743922784, gettid: 41841--> different thread id to:
281474727014496  --> different gettid to: 41833
thread 15: 281474718560352, gettid: 41842--> same thread id  --> different
gettid to: 41834
...

and:

OMP_PROC_BIND=true ./gcc_llvmomp

...
thread 0: 281474842439712, gettid: 41863--> same thread id  --> same gettid
thread 1: 281474836063584, gettid: 41864--> same thread id  --> same gettid
thread 2: 281474827605472, gettid: 41865--> same thread id  --> same gettid
thread 3: 281474819147360, gettid: 41866--> same thread id  --> same gettid
thread 4: 281474810689248, gettid: 41867--> same thread id  --> same gettid
thread 5: 281474802231136, gettid: 41868--> same thread id  --> same gettid
thread 6: 281474793773024, gettid: 41869--> same thread id  --> same gettid
thread 7: 281474785314912, gettid: 41870--> same thread id  --> same gettid
thread 8: 281474439833824, gettid: 41871--> same thread id  --> same gettid
thread 9: 281474431375712, gettid: 41872--> same thread id  --> same gettid
thread 10: 281474422917600, gettid: 41873--> same thread id  --> same gettid
thread 11: 281474414459488, gettid: 41874--> same thread id  --> same gettid
thread 12: 281474406001376, gettid: 41875--> same thread id  --> same gettid
thread 13: 281474397543264, gettid: 41876--> same thread id  --> same gettid
thread 14: 281474389085152, gettid: 41877--> same thread id  --> same gettid
thread 15: 281473902963808, gettid: 41878--> same thread id  --> same gettid
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.