Limiting the Number of Cores of Execution on a Windows System

How to Limit the Number of Cores of Execution on a Windows Multicore System


If you have a Windows test machine with a large number of CPU cores that you wish to use for testing performance and compatibility with a lesser number of CPU cores you may be able to use that one machine to test several multicore scenarios. For example, an 8-core machine can be configured to restrict Windows from using all 8-cores, forcing it to use, for example, only 4, 2, or even one core in the machine. This technique can be used to more evenly compare system performance by varying the number of cores on the machine and to verify proper operation or scalability of your software for a variety of multicore configurations.

Note:
You will have to modify your BOOT.INI file or Boot Configuration Data (BCD on Windows Vista) to setup a machine for this purpose.

To restrict the number of CPU cores Windows will use on a multicore machine follow these instructions:

1.) Determine how many logical CPUs are in your system. Do this by opening the following registry key:

HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor

There will be one subkey for each logical CPU. The precise number of logical CPUs depends on the number of cores in your processor(s) and whether or not those cores are using Hyper-Threading technology. For example, a four-core machine with Hyper-Threading technology can appear to have eight logical CPUs (two threads per core * four cores = eight logical CPUs or threads).

2.) On a Windows XP system, edit the BOOT.INI file located in the root directory of your boot drive (usually C:).

Find the line in the [Operating Systems] section that boots the Windows system you are using (on systems with multiple Windows boot partitions you must take care to identify the correct line). This line usually looks something like the following:

multi(0)disk(0)rdisk(0)partition(1)WINDOWS="Microsoft Windows XP" /fastdetect

3.) Add one (or more) lines with the /NUMPROC parameter to create a second boot option that limits Windows to the desired number of logical cores.

For example assuming an eight logical CPU system (eight possible execution threads), you might want to add the following boot scenarios (new text is marked in bold):

multi(0)disk(0)rdisk(0)partition(1)WINDOWS="Microsoft Windows XP" /fastdetect
multi(0)disk(0)rdisk(0)partition(1)WINDOWS="Microsoft Windows XP, 1 core" /fastdetect /NUMPROC=1
multi(0)disk(0)rdisk(0)partition(1)WINDOWS="Microsoft Windows XP, 2 cores" /fastdetect /NUMPROC=2
multi(0)disk(0)rdisk(0)partition(1)WINDOWS="Microsoft Windows XP, 4 cores" /fastdetect /NUMPROC=4
multi(0)disk(0)rdisk(0)partition(1)WINDOWS="Microsoft Windows XP, 6 cores" /fastdetect /NUMPROC=6

This configuration would allow you, at boot time, to choose to boot Windows in 1-threads, 2-threads, 4-threads, 6-threads and "all-threads" modes. Your Windows configuration is identical other than the number of execution threads available.

Note:
you should modify each description so you can easily identify the specific boot options at boot time.

For full details of all of the BOOT.INI options see the SysInternals website (now part of Microsoft) at:
http://www.microsoft.com/technet/sysinternals/information/bootini.mspx

To configure your Windows Vista system to include a second boot option you will need a BCD editor. For example, you can use VistaBootPRO (www.pro-networks.org) to create and name additional boot entries in your Vista BCD and then use the Microsoft msconfig tool to configure each of your boot options.

-- Configure the number of threads with msconfig.
-- Use VistaBootPRO to create and name those boot options.

Using msconfig seems to work better than VistaBootPRO to configure boot options. VistaBootPRO is easier to use to create additional BCD boot entries.

Some Related Articles,

Using KMP_AFFINITY to create OpenMP thread mapping to OS proc IDs

Control OpenMP thread affinity with ippSetAffinity function

/sites/products/documentation/studio/composer/en-us/2009/compiler_c/optaps/common/optaps_openmp_thread_affinity.htm

For more complete information about compiler optimizations, see our Optimization Notice.