Tomasz Niedabylski Tomasz Niedabylski - 2 months ago 48
C++ Question

How to set /MP in MSBuild with a specified cpu count

I'm trying to speed up building of a C++ project consisting of multiple large files. Adding

<MultiProcessorCompilation>true</MultiProcessorCompilation>
to *.vcxproj file works and speed improvement is nice but since it uses all available cpus, it can make my machine unresponsive for a while.

Is there any way of passing an argument to /MP option of the compiler through a *.vcxproj project file (since I want to get the benefit when building using Visual Studio)?

Refactoring / splitting the project is not an option at this time unfortunately.

Answer

You can set the max number of the processes that will be used during compilation on projects's configuration properties, C/C++ - Command Line, Additional Options:

/MP[processMax]

where processMax is the required number.

As Microsoft states

If you omit the processMax argument, the compiler retrieves the number of effective processors on your computer from the operating system, and creates a process for each processor

So, you should experiment with the processMax value, to decide which is best suited for your system in order to be responsive.

When you specify /MP [processMax] e.g. /MP4 in project's configuration properties ( C/C++ - Command Line, Additional Options) this is actually saved in vcxproj file as: <AdditionalOptions>/MP4</AdditionalOptions> in <ClCompile> element.

Comments