CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2007

    Running an application on multiple CPUs

    I have a multi-threaded application, written in Visual Studio C++.
    However, I'm told that, when running on a system with multiple CPUs (a server), only a single CPU is used by the application.
    Is there some setting within Visual Studio that allows applications to be run on all available CPUs?

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: Running an application on multiple CPUs

    It depends upon how the program has been coded. If it is coded as a multi-threaded program, then the number of threads used is dependent upon how the program uses threads. It might be coded to just use 2 or 4 or ??? threads - irrespective of the number of available cores. You might have say 2 physical CPU chips with each having say 4 cores - ie 8 cores in total. The program might utilise all 8 cores or just 2 or?? as per the program coding for using multiple threads. It's also possible - and common- for programs to use more threads than available cores.

    A single thread can only run on one CPU at a time. A single thread cannot be shared amongst CPUs. But multiple threads are shared amongst available ones. If your program uses say 6 simultaneous threads then if there are 6 or more available CPUs then each thread will probably run on it's own CPU - depending upon the overall processes/threads running on the system in total.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.3.4)

  3. #3
    Join Date
    Feb 2017

    Re: Running an application on multiple CPUs

    Quote Originally Posted by rmirani View Post
    However, I'm told that, when running on a system with multiple CPUs (a server), only a single CPU is used by the application.
    It is decided by the OS. In the case of Windows, Microsoft says this,

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