Meta

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!

This entry was posted
on Thursday, October 11th, 2007 at 5:01 pm and is filed under Programming.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

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.).

Unfortunately, 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