57

How can I get VS 2010 to run more than one C++ compile process at a time? I mean building object modules in parallel; I'm not interested in building more than one project at a time (I know about Tools > Options > Build and Run < Maximum number of parallel project builds, but that doesn't do what I want).

Basically, I'm looking for Visual Studio's equivalent of "make -jN".

Jamal
  • 763
  • 7
  • 22
  • 32
Ross Smith
  • 3,719
  • 1
  • 25
  • 22

6 Answers6

34
  1. Tools -> Options
  2. Projects and Solutions\VC++ Project Settings
  3. Maximum concurrent C++ compilations

Also, as Ross Smith said in the comments, you also need to turn on the "Multiprocessor compilation" option on the project:

  1. Project properties
  2. Configuration Properties > C/C++ > General
  3. Multi-Processor Compilation
  4. Profit!
Mathieu Pagé
  • 10,764
  • 13
  • 48
  • 71
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
  • 2
    That doesn't have any effect. Setting it to 0 (the default, which is supposed to mean "use all cores") or 4 (the actual number of cores) doesn't make any difference, it still builds only one module at a time. – Ross Smith May 30 '11 at 04:22
  • 2
    @Ross: When that kind of parallel building is in effect, it doesn't show in the console output (unlike project parallel builds). Did you verify that it's not happening based on looking at task manager or are you just not seeing anything on the console? You should see the same number of `cl.exe`s as you have cores. – Billy ONeal May 30 '11 at 04:24
  • I watched it in Process Explorer, there's only one cl.exe process and it's only exercising one of the four cores. – Ross Smith May 30 '11 at 04:29
  • 6
    Its important to note that the `/MP` (aka multithreaded compilation) flag is not compatible with certain other build flags, such as incremental compilation. @billy: it should be showing messages from each compilation thread(`thread> message`) for each translation unit, unless they removed that feature since vs08... – Necrolis May 30 '11 at 04:35
  • @Necrolis: My understanding was that the threaded output was only for project parallel builds, rather than translation unit parallel builds. Good to know. – Billy ONeal May 30 '11 at 04:51
  • 11
    It turns out there's an option I missed in the project properties, Configuration Properties > C/C++ > General > Multi-Processor Compilation. Turning this on kind of works - it builds some of the modules in parallel, but still insists on going back to a single thread for others, and I haven't figured out what might be causing the difference. It's also a pain having to set it manually for every project, but I guess half a solution is better than none. – Ross Smith May 31 '11 at 23:39
  • 6
    You can Shift+select multiple projects and edit them all at the same time. – Eugene Apr 06 '12 at 08:43
18

There are two switches that must be set in order to make VS build using multithreading (both are project-specific):

  • project properties->C/C++->General->Multi-processor Compilation set to: Yes (/MP)
  • project properties->C/C++->Code Generation->Enable Minimal Rebuild set to: No (/Gm-)

Check also Your Tools->Options->Projects and Solutions->VC++ Project Settings->Maximum concurrent C++ compilations setting. Default value is 0 which enables VS to use as many concurret compilations as possible.

jskierbi
  • 1,635
  • 1
  • 14
  • 22
15

Necrolis' comment seems the correct solution.

/MP (Build with Multiple Processes)

The /MP option causes the compiler to create one or more copies of itself, each in a separate process. These copies simultaneously compile the source files. Consequently, the total time to build the source files can be significantly reduced.

Note that you can set it at project level (and thus it will apply to all files in it) as well as to the individual files, useful for instance if you need to use #import.

In particular, /MP is usually not compatible with precompiled headers, or sources using #import; in this case, you can still set /MP flag on the project, and then clear it on the single files (usually, stdafx.cpp, and any file using #import).

rob
  • 36,896
  • 2
  • 55
  • 65
5

Here is what I did

1) Go to Tools->Options than under "Project And Solutions"->"Build And Run" for me it had the number of cores. Although at first i thought this was all i needed to do but it isnt

2) Right click your project and select properties. Under "configuration properties"->"C/C++"->"Command Line" enter /MP4 where 4 is the number of cores you have. You'll get a warning about flags not being compatible so we have another step

3) Go to Under "configuration properties"->"C/C++"->"Code Generation" there is "Enable minimum rebuild". Change that to no.

Rebuild and you should see multiple CL processes in your task manager.

schoetbi
  • 12,009
  • 10
  • 54
  • 72
4

jom is the tool you are looking for.

From the wiki at: http://qt-project.org/wiki/jom

jom is a clone of nmake to support the execution of multiple independent commands in parallel. It basically adds the -j command line switch similar to GNU make.

While most of the documentation is aimed at Qt developers trying to speed up Qt library builds on windows, jom should work perfectly well in non Qt projects too, as long as you have an nmake compatible makefile.

The wiki page has binaries you can download, and you call jom as you would nmake.

Rian Sanderson
  • 6,306
  • 4
  • 29
  • 34
  • Unfortunately i found that jom is pretty buggy and often don't get that a process has terminated hanging itself until the worlds end. – Lothar Feb 25 '14 at 05:59
0

I see! Your requirement is building single project in parallel threads.

I find Shark compiler Control plugin very useful

Digital_Reality
  • 4,488
  • 1
  • 29
  • 31