-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable the /MP MSVC compiler argument for parallel compilation #1846
enable the /MP MSVC compiler argument for parallel compilation #1846
Conversation
Does the build generator not produce one compiler invocation per source file? |
@LebedevRI it won't spawn more than there are source files, but /MP on it's own is driven by the number of logical cores on the host machine:
It can be limited by adding a number e.g /MP2. What we normally do with this setting is work out the number of cores on the machine, then subtract 2. I can implement that here if required. |
My question is: is that generator effectively always in Unity build / jumbo build mode? But i'll leave this for @dmah42. It's probably fine i guess. |
An example might be easier. Assume we have a VS solution with three projects, each one builds an exe and there are no dependencies between them. If we pass -j3 at the cmake build stage, then MSBuild will attempt to build all three projects in parallel. If each project has 10 cpp files, without /MP each source will be built in a serial fashion i.e we'd use 3 cores. By specifying /MP you can then enable parallel compilation. So if we had a machine with 30 cores, in theory the above example would use all of them (3 projects x 10 source files each) Hope that clarifies? |
I see. Sounds like the solution is to use a better generator ( |
ninja might be a solution but if folks want to use msbuild this seems like a healthy improvement. |
Huh, that sounds weird. |
As detailed here:
https://learn.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes?view=msvc-170
This enables parallel compilation. The build generator can already parallelise at the project level i.e -j10 for example, but this enables parallel compilation.
On my machine, times without this change:
And times with: