Click to See Complete Forum and Search --> : Proof of core utilization in a program


humble_learner
October 6th, 2008, 10:50 PM
Hi,

Basically, I wanted to display to an audience how an application having multiple tasks executing in multiple threads pans out across multiple cores.

Basically, imagine that I have two for loops running from 0 to 10,00 and printing some data in the loop. Now, I implement two threads (native threads) in which I run the loops.

Now, I want to show the audience that the two threads are running on separate cores (I have a Centrino Duo machine) instead of timesharing on the same core.

Now, is it possible to provide any visual proof of this fact on Windows - programatically on using the Windows Task Manager (Performance) window ?
Basically, wanted a simple implementation and proof because this is for an introduction to beginners in the world of multicore and parallel programming.

Thanks.

CBasicNet
October 7th, 2008, 02:45 AM
You can see in the task manager that PC with 2 cores will have 2 CPU utilization graphs and PC with 4 cores will have 4 CPU graphs. You can show that the all the CPUs are fully utilized if the graphs are all at 100% utilization.

But from 0 to 1000 loop, I dun think you can utilize the CPUs to 100%.

Lindley
October 7th, 2008, 08:55 AM
The best approach would be to do a parallelizable math-heavy algorithm. And spare the IO----that just slows things down.

coricori
October 9th, 2008, 07:11 AM
I think i have a question related to that but my question is:
If i have two functions, running "same time" how can i make that each function to run on separate cores?

Can i do that, or the OS is responsable for that. I think they have to be some API's in order to do that.

MrViggy
October 9th, 2008, 04:02 PM
I forget the function calls, but search for "processor affinity" on the MSDN.

Viggy

VladimirF
October 9th, 2008, 06:54 PM
Can i do that, or the OS is responsable for that. I think they have to be some API's in order to do that.You CAN do that (as MrViggy suggested) by calling SetThreadAffinityMask for each thread.
However, you SHOUD let OS decide what core to run your stuff on.
I am pretty sure that if the cores are available, the OS will use as many as there are concurrent threads running at the time.

coricori
October 11th, 2008, 08:13 AM
I forget the function calls, but search for "processor affinity" on the MSDN.

Viggy

How do you guys use MSDN? Did you had to solve this kind of problem, or how did u know that keyword to use( and now to recommend me )?

I tried the online version of MSDN, and I really dislike it. I couldn't imagine how to use it in a proper and productive way.