Sam's Blog

11 Oct

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! 🙂

Location of the MP build option

6 Responses to “Multi-processor building in Visual Studio 2005”

  1. 1
    Tom Says:

    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.

  2. 2
    280Z28 Says:

    Sorry for the confusion. I added a screenshot of where this option goes. 🙂

  3. 3
    ftrocchi Says:

    Some questions about this:

    1. How do you “setting the number of parallel project builds to 2”?
    2. Do you know if this is available in Visual Studio 2k3?
  4. 4
    Source-level parallel build in Visual Studio 2005 | veracity Says:

    […] 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 […]

  5. 5
    Andy Says:

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

  6. 6
    Andy Says:

    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 🙂

    Andy

Leave a Reply

© 2024 Sam's Blog | Entries (RSS) and Comments (RSS)

Your Index Web Directorywordpress logo