CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2006
    Posts
    384

    Proof of core utilization in a program

    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.

  2. #2
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    Re: Proof of core utilization in a program

    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%.

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Proof of core utilization in a program

    The best approach would be to do a parallelizable math-heavy algorithm. And spare the IO----that just slows things down.

  4. #4
    Join Date
    Aug 2007
    Posts
    52

    Re: Proof of core utilization in a program

    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.

  5. #5
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Proof of core utilization in a program

    I forget the function calls, but search for "processor affinity" on the MSDN.

    Viggy

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Proof of core utilization in a program

    Quote Originally Posted by coricori
    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.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    Join Date
    Aug 2007
    Posts
    52

    Re: Proof of core utilization in a program

    Quote Originally Posted by MrViggy
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured