简体   繁体   中英

Single-threaded build for specific object file

I work on a very large C++ project that takes 20-30 minutes to fully build with all cores enabled. The problem is that there are some very specific source files that take up an enormous amount of memory to build (around 5 GB), so what happens is that, whenever the build reaches those source files and tries to build them all at the same time, the memory usage skyrockets and if the machine doesn't have enough memory, the system starts swapping and the compilation considerably slows. However, if I try to reduce the amount of threads, the compilation run time could end up reaching a couple of hours or more -- and most of the source files don't really need that much memory to compile.

The ideal scenario would be: go on with the multi-process compilation, then fall back to a single compilation process once the offending files start to compile. So how do I tell CMake that I want a specific source file to be compiled without any other compilations in parallel?

EDIT: Linking is fine, the memory spike happens while compiling the offending source cpp files.

An alternative solution if you can't find a cmake flag.

I had a similar problem to this, I used a tool called distcc to solve the problem.

You won't see much benefit with compilation times with lots of smaller projects, however it sounds like you have a load pattern which would be very suited to distributing over a cluster of build workers.

However it it's bottle neck in the linker your milage will vary.

units/modules rather than one large monolithic C program, or scale up (give your machine more memory).

https://github.com/distcc/distcc

distcc doesn't work well for all types of projects, but your sounds large enough that it will make distributing it over the network worth while.

If you do try it, post some compile times. I'd be interested to see the difference.

good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM