Question

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.

Était-ce utile?

La solution

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.

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top