Multi-processor building in Visual Studio 2005
Today I learned about a very interesting (undocumented) compiler flag in Visual Studio 2005. With the simple addition of /MP
to the C++ Additional Options for your project, the compiler will take advantage of multiple processors. Obviously you need a multi-processor machine for this to work.
So how much difference are we talking? The project I’m currently working on took 5:00 to build on my FX-70 machine at work. Adding this flag dropped the number to 1:53. In compiling our full solution (7 projects), setting the number of parallel project builds to 2 and adding the /MP flag took 14 minutes 20 seconds (an overall improvement of 3 minutes from having 3 project builds an no /MP flag). The IDE remained responsive during the build (the first thing I had to test).
Definitely made my day better! 🙂
Where do you set the /MP flag? The only place I could see was in Project->Properties->Configuration Properties->C/C++->Command Line->Advanced Options. Is this what you mean?
Thanks.
October 31st, 2007 at 5:36 amSorry for the confusion. I added a screenshot of where this option goes. 🙂
October 31st, 2007 at 1:49 pmSome questions about this:
[…] what about VS 2005? I did some more searching and, lo and behold, found this blog entry which says the /MPÂ option is also available, but undocumented, in Visual Studio […]
February 15th, 2008 at 5:28 am@ftrocchi:
In the Visual Studio options dialog, go to Project and Solutions | Build and Run. There is a TextBox near the top of the window, with the text “maximum number of parallel project builds” next to it. Set this to the maximum number of projects that you want Visual Studio to build at one time. I believe by default this is set to the number of CPUs you have (including cores, hyperthreading, etc.).
I’m pretty sure that this is a feature new to Visual Studio 2005.
July 9th, 2008 at 2:50 pmUnfortunately, the “/MPx” switch is beta or “texhnology preview” in VS2005.
There are a host of undefined issues surrounding its use.
For instance, if you build with Compile and Continue or fast (not full) Rebuild then the compilations might be invalid.
We used the switch on our production build server for a while but noticed that every once in a while it would cause the build process to hang indefinitely (needing a reboot)
In VS2008 Microsoft fixed a few issues and worked around some others by enforcing that you can no longer set invalid combinations of compiler switches. For instance, since compile-and-continue was causing problems with “/MPx”, they made it an error to have those two configured at the same time.
Because of the “undefined behavior” in VS2005, I’m dropping “/MP4” from all our projects until we upgrade to VS2008 or VS2010.
THe syntax is to say “/MP” followed by the number of processors you want to use, so “/MP2” is 2-processors and “/MP4” spreads over four processor.
Sadly I cannot test if “/MP64” works, but I salivate thinking about it 🙂
Andy
April 15th, 2009 at 1:10 pm