Does Go count virtual cores, not physical ones?

I have Go code that I am testing on my Macbook (Intel Core i5 processor with two physical cores).

Go runtime.NumCPU()gives 4 because it considers "virtual kernels"

I don’t know much about virtual kernels in this context, but my tests show that multiprocessing is only 2 times faster when I configure my code using

runtime.GOMAXPROCS(runtime.NumCPU())

I get the same performance if I use 2 cores instead of 4. I would publish the code, but I think it is largely irrelevant to my questions, namely:

1) is this normal?

2) why, if so, do multiple virtual cores benefit a machine like my macbook?

Update:

In case this matters, in my code there are the same number of procedures as what you install runtime.GOMAXPROCS(), the tasks are completely parallel, do not have interdependencies or general state. it works as its own compiled binary.

+4
source share
1 answer

1) - is this normal?

If you mean virtual kernels that map to runtime.NumCPU(), then yes, at least in the sense that programs written in C, as well as those that run on top of other runtimes such as the JVM, will see the same number of processors . If you mean performance, see below.

2) , , , macbook?

, . , , , , 3D- . , HT (- ). hyper-threading .

- , HT . , HT .

+6

All Articles