简体   繁体   English

特定 object 文件的单线程构建

[英]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.我在一个非常大的 C++ 项目上工作,在启用所有内核的情况下完全构建需要 20-30 分钟。 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.问题是有一些非常具体的源文件占用了大量的 memory 来构建(大约 5 GB),所以发生的情况是,每当构建到达这些源文件并尝试同时构建它们时, memory 的使用量猛增,如果机器没有足够的 memory,系统开始交换,编译速度大大减慢。 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.但是,如果我尝试减少线程数量,编译运行时间最终可能会达到几个小时或更长时间——而且大多数源文件实际上并不需要那么多 memory 来编译。

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.理想的情况是:go 启动多进程编译,然后在有问题的文件开始编译后退回到单个编译进程。 So how do I tell CMake that I want a specific source file to be compiled without any other compilations in parallel?那么如何告诉 CMake 我希望在没有任何其他并行编译的情况下编译特定的源文件?

EDIT: Linking is fine, the memory spike happens while compiling the offending source cpp files.编辑:链接很好,memory 尖峰发生在编译有问题的源 cpp 文件时。

An alternative solution if you can't find a cmake flag.如果您找不到 cmake 标志,则另一种解决方案。

I had a similar problem to this, I used a tool called distcc to solve the problem.我有一个类似的问题,我使用了一个名为 distcc 的工具来解决这个问题。

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.但是,它是 linker 的瓶颈,您的里程会有所不同。

units/modules rather than one large monolithic C program, or scale up (give your machine more memory).单元/模块,而不是一个大型的单片 C 程序,或者扩大规模(给你的机器更多的内存)。

https://github.com/distcc/distcc 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. distcc 不适用于所有类型的项目,但是您的声音足够大,以至于通过网络分发它是值得的。

If you do try it, post some compile times.如果您确实尝试过,请发布一些编译时间。 I'd be interested to see the difference.我很想看看有什么不同。

good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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