I'm sure you have come across C/C++ projects that contain thousands of lines of code, split into many source and header files. Not 5 or 10, we are talking about hundreds or even thousands of files. One of the productivity hits in a software project is the time required to compile these source files. Depending on the amount of code, the time may range from seconds to hours. While some cunning developers may take advantage of this (see the comic below), others may find it frustrating to wait for the compilation to finish.

compiling_funny

Image source: xkcd

What many programmers don't know is that most of the modern compilers have option to utilize the multi-core architecture of the processor to speed up the compilation process. This enables multiple source files to be compiled simultaneously, thereby reducing the project build time significantly. We can specify the maximum number of parallel compilations or we can leave it to the compiler to select the optimal number. Latter approach is usually preferred. Here is how multiprocessor compilation can be enabled in different compilers:

Visual Studio 2008

VS 2008 multi core compilation

Go to Project Properties > C/C++ > Command Line.

Specify the /MP flag in Additional Options.

Visual Studio 2010

VS 2010 multi core compilation

Go to Project Properties > C/C++ > General

Set the option Multi-processor Compilation to Yes

Eclipse

This feature is not just limited to VS only. Any IDE should have an option to enable multi-core compilation. I wonder why not it's enabled by default?

Go to Project Properties > C/C++ Builds

Open the Behavior tab.

Check the option Use parallel build and select Use optimal jobs number.

To see the difference in time, we compiled a project containing 18 .cpp files, with and without the /MP flag on Visual Studio 2010 with an Intel Core i7 2600 CPU (8 logical processors). The timings are as follows:

compile_timings

Sadly there's no global setting in IDE (there should be) to enable multi processor compilation by default. I recommend enabling this feature with every new project you create to save handsome amount of time. Unless of course you prefer the status quo 😛