문제

I noticed, that MingW and GCC compilers use multiple cores if available.

For example:

for (long i = 0; i < 100000; ++i)
{
    some_complicated_calculation();
}

If I open up a Task Manager / System Monitor, I can see that multiple (for me: 2) cores are used.

How the compiler decides, which code can run on multiple cores?
How do I force the compiler, to use only one core?

EDIT

My code does not contain any multithreaded code.
I'm curious why my program (not the compiler) is using multiple cores.

도움이 되었습니까?

해결책

It is using a single core as long as there is nothing special inside some_complicated_calculation() that creates threads or uses async (C++11) or similar.

The activity you see on the task manager cannot be related to the executable that iterates. It could be totally unrelated to what you are working on.

다른 팁

Looks like thread_bind_to_processor provided in GNU software radio is what you're looking for: http://gnuradio.org/doc/doxygen/namespacegr_1_1thread.html#aab5195edcd94db5c71ecbfef9d578fb7

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top