-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: NumCPU always 1 when using CGO with libgomp [linux/arm64 - openstack virtualization] #47365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@willliu Tried this on my machine with and without ➜ /tmp go run main.go
number of current logic cpus: 24
➜ /tmp go version
go version go1.16.6 linux/amd64 My environment info ➜ /tmp uname -a
Linux turing 5.12.8-051208-generic #202105281232 SMP Fri May 28 12:35:52 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
➜ /tmp gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
Thank you for your reply, I later checked my bare metal, it is correct (same go, gcc, os). The original case is in cloud, so I suspect something with hypervisor is involved. P.s. my machines are ARM64 instead of AMD64. |
Go should be reading and parsing the value from https://linux.die.net/man/2/sched_getaffinity |
Thank you Alex, after check the source code, runtime.NumCPU traces back to Now, I suspect that in some case cgo's linking with -lgomp makes btw, I tested on the error prone machine 1, with the following C++ code linked with openmp: main.cpp
$ g++ main -fopenmp -lgomp -O3 -o main It gives the correct number of logic cpus, so openmp seems work. |
|
Alex, you pointed out the right direction, and I indeed found the source of error (and miracle). main.c (adapted from stackoverflow.com/questions/10490756/how-to-use-sched-getaffinity-and-sched-setaffinity-in-linux-from-c)
$gcc -o main main.c Now linked with -lgomp This agrees with golang's behavior previously, that Thanks again Alex, |
I would guess gomp is calling |
@n4j @AlexRouSg Thank you all, setting environment |
It looks like this has been resolved, and it looks like there is no change required to the Go source code. Closing. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?[machine 1 (in cloud) - error]
go env
Outputgcc --version & numactl -H & uname -a
Outputsudo dmidecode
Output[machine 2 (bare metal) - correct]
go env
Outputgcc --version & numactl -H & uname -a
OutputWhat did you do?
main.go:
$go run main.go
On machine 1, there are 16 logic cpus, but when linked with cgo -lgomp, runtime.NumCPU gives 1. If one comment out -lgomp, the output is correct. Machine 1 is running virtually in cloud.
On machine 2, there are 4 logic cpus, when linked with cgo -lgomp, runtime.NumCPU gives 4 as expected. Machine 2 is running in bare metal.
What did you expect to see?
[machine 1]
number of current logic cpus: 16
[machine 2]
number of current logic cpus: 4
What did you see instead?
[machine 1 - error]
number of current logic cpus: 1
[machine 2 - correct]
number of current logic cpus: 4
The text was updated successfully, but these errors were encountered: