Solved Multicore and multithreading programming

Hi All,

Please bear with me while I explain this, this is newbie thingy.

I have Intel I5 multi-core.

What I am trying to understand is that if I want to take advantage of those cores when writing a program, I need to use multi-threading? Or is it parallel programming technique?

I am trying to learn threads. While I can write programs and examples but I want to understand the core bit.

I understand that the kernel is responsible for binding threads to cores?
or is it processes only?

How can I see how cores are utilized?

For example, suppose my programs have 8 long running threads (to simplify), is it possible to make them use those cores? or is it the kernel responsibility to do that?

in FreeBSD how can I see the statistics for those cores?

Thanks for your patience :)
 
Hi,

[...] if I want to take advantage of those cores when writing a program, I need to use multi-threading? Or is it parallel programming technique?

Yes, the only way to utilize more than one core is to execute more than one thread. However, it does not mean you have to manage the threads yourself. Some libraries (like OpenMP, or std::async from C++) can do that for you.

[...] I understand that the kernel is responsible for binding threads to cores?

Correct.

[...] For example, suppose my programs have 8 long running threads (to simplify), is it possible to make them use those cores? or is it the kernel responsibility to do that?

You can restrict running some threads on some specific cores (see cpuset(2)). However, you should not usually do that.

[...] How can I see how cores are utilized?
[...] in FreeBSD how can I see the statistics for those cores?

You can use top -PH to see the statistics. P shows CPU usage per core, H shows individual threads of the processes.

HTH
 
Back
Top