Sign in to follow this  

Visual C++ 2k5: faster compile with dual core?

This topic is 3933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I recently got a dual core CPU, so I wanted to see if VC++ would compile my projects faster. Unfortunately it looks like the VC++ compiler is single threaded. This seems really surprising to me- VC++ 2005 is fairly modern, and it seems to me like it wouldn't have been that hard for Microsoft to make VC++ launch 2 instances of CL.exe at the same time. I'm no expert on compilers but AFAIK compiling 2 different CPP files can be done completely in parallel, although maybe linking needs to be done in a single thread. So, does anyone know if there's a patch or something to make VC++ smarter about this? If not, maybe this could be done using a make file of some sort, that knows to launch 2 instances of the compiler at a time? Thanks Kuro

Share this post


Link to post
Share on other sites
there's no patch but there are various VS pluggins. google around. off the top of my head I only know of Incredibuild which i think you have to buy.

There was also a thread about this a couple weeks ago, also search on the site.

-me

Share this post


Link to post
Share on other sites
If the files are completely independent, then yes. But what if for some reason they depend on each other or both include common files? Then parallelization won't be a benefit but a detriment. In short, single threaded compilation I believe is the way to go.

Share this post


Link to post
Share on other sites
VS 2005 has an option to compile multiple projects in parallel (Tools, Options, Projects and Solutions\Build and Run\parallel project builds), but I believe files in a single project compile sequentially.

Share this post


Link to post
Share on other sites
Quote:
Original post by Alpha_ProgDes
If the files are completely independent, then yes. But what if for some reason they depend on each other or both include common files? Then parallelization won't be a benefit but a detriment. In short, single threaded compilation I believe is the way to go.


.cpp files are always compiled completely separately; you should never have dependencies between .cpp files (only with .h files or if you are doing a unity build solution). the compiler compiles all the .cpp files into separate .obj files which are then linked together; which is why you can compile in parallel but not link in parallel.

With incredibuild at work I compile about 15 .cpps in parallel (it's a network parallel compile solution). With incredibuild it takes me 5-7min to compile our game; without it takes about 30min. It most definitely makes a huge difference.

[EDIT: i think you mean concurrent reads on a common header would stall one thread. I'm not sure how the parallel compile plugins handle this but they most certainly do. Either way it makes a really big difference to parallel compile]

-me

Share this post


Link to post
Share on other sites
Palidine- Thanks very much! I gotta work on my googling skills 'cause I spent 15 minutes and couldn't find a thing... That incredibuild looks pretty sweet!

mutex- Nice tip! Thanks, I think you're right though that it doesn't apply to compiling different files in parallel because mine was already set to 2, but it was doing a single thread.

I just did some more searching to see if it would be terribly difficult to come up with a custom build process that takes advantage of multiple cores. It looks like someone tried it, but the problem was that when you compile a CPP file, it doesn't just create an OBJ file--- it also writes to the PDB file that contains all the debugging junk. So, compiling 2 CPP files at the same time doesn't work so well because they both try to write to the PDB file simultaneously.

This guy worked around that problem by using the /Fd flag to create an individual .PDB file for each .OBJ file... it worked, but then the total size of all the PDB files was ridiculously large (like 300 MB), and that also made link time 50% longer.

Hmm, maybe MS will implement its own parallel compiling feature in the next version of VC++ *crosses fingers*

[Edited by - Kuro on March 7, 2007 12:11:30 AM]

Share this post


Link to post
Share on other sites
Just came across this: Multi-processor builds in Orcas.
Quote:
In addition to maintenance work, we found time to implement one feature that we hope you’ll find useful. Build times always prove to be a major pain point for our customers, so we have done our best to try to provide technologies to mitigate the cost of building large projects such as the managed incremental build feature (formally called asmmeta) that Curt Carpenter recently blogged about. With the growing presence of multi-core computers in both the developer and consumer space, exploiting that added power can help reduce build times significantly. To that end, we’ve added a new switch to the compiler, /MP, to enable multi-process building at the source file level.

/MP works by exploiting the fact that translation units (a source file coupled with its includes) can be compiled independently of each other (up to link time where all object files need to be present). Since we can compile each translation unit independently, we can parallelize the compilation by spawning multiple processes to handle a batch of source files. This is precisely what /MP does; when you issue /MPn to the compiler, it spawns up to n processes to handle the source files passed to it. The compiler is smart enough to spawn only as many processes as necessary, so if you specify three source files on the command-line and invoke the compiler with /MP4, then the compiler only spawns 3 processes. By default, /MP takes n to be the number of effective processors on the machine.
Note that this is a Visual C++ feature for the version of Visual Studio after 2005.

Share this post


Link to post
Share on other sites
Quote:
Original post by mutex
Just came across this: Multi-processor builds in Orcas.
Quote:
In addition to maintenance work, we found time to implement one feature that we hope you’ll find useful. Build times always prove to be a major pain point for our customers, so we have done our best to try to provide technologies to mitigate the cost of building large projects such as the managed incremental build feature (formally called asmmeta) that Curt Carpenter recently blogged about. With the growing presence of multi-core computers in both the developer and consumer space, exploiting that added power can help reduce build times significantly. To that end, we’ve added a new switch to the compiler, /MP, to enable multi-process building at the source file level.

/MP works by exploiting the fact that translation units (a source file coupled with its includes) can be compiled independently of each other (up to link time where all object files need to be present). Since we can compile each translation unit independently, we can parallelize the compilation by spawning multiple processes to handle a batch of source files. This is precisely what /MP does; when you issue /MPn to the compiler, it spawns up to n processes to handle the source files passed to it. The compiler is smart enough to spawn only as many processes as necessary, so if you specify three source files on the command-line and invoke the compiler with /MP4, then the compiler only spawns 3 processes. By default, /MP takes n to be the number of effective processors on the machine.
Note that this is a Visual C++ feature for the version of Visual Studio after 2005.

Microsoft Pre-release Software Visual Studio Code Name "Orcas" - March Community Technology Preview (CTP)

Share this post


Link to post
Share on other sites

This topic is 3933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this