cogito ergo vagus

February 15, 2008

Source-level parallel build in Visual Studio 2005

Filed under: software — vagus @ 10:28 am
Tags: , ,

I regularly work with Microsoft Visual Studio 2005 with SP1 on my Pentium 4 single-core non-hyperthreading based PC and occasionally run some builds on an Athlon 64 X2 dual core based PC. I noticed the compiler (cl.exe) is a single process with a single thread running, even on the dual core.

I did some digging around to see if I could enable parallel (multi processor) builds to take advantage of the extra idle core to speed up my builds and came across the following links:

Visual Studio 2005 tour and MSDN multiprocessor project builds

I was glad to find the /Mx  option where x is the maximum number of project builds you want to run in parallel. I dug around the codebase and realised the build script already had /M8 specified as a parameter to the call to vcbuild.exe. I even opened up the project in Visual Studio 2005 and the setting was at 2 (since this is a dual core)  as expected.

But the build still seemed to be running a single thread and not using the extra core :-(

I then re-read the links above more carefully and saw that the option is for parallel project builds so it would only work for multiple projects and not for many source files in a single project.

I did the customary STFW/JFGI and found the new /MP option which is a part of the new Visual Studio 2008 and this option enables source level multiprocessor parallel builds.

But 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 2005!

Adding it to the build script’s parameter list for vcbuild.exe didn’t work, but adding it in the “additional options” window in the Visual Studio 2005 project worked and now doing a build would launch three processes of cl.exe, one which had 45 threads but took very little CPU cycles, and the other two were single threaded and utilised a CPU core each to the fullest! That was my Homer Simpson “woohoo” moment of the day :-)


Blog at