【问题标题】:how to: make -j x // where x is automatically determined如何: make -j x // 其中 x 是自动确定的
【发布时间】:2012-06-12 07:23:15
【问题描述】:

阅读此问题的答案后: Make "make" default to "make -j 8"

我想知道是否有办法让 -j 选项自动使用正确数量的编译线程?

所以我说makemake 命令本身使用 6 或 4 或 8 个线程,具体取决于硬件?

【问题讨论】:

  • 正确的编译线程数是什么意思?
  • @maba 通常建议使用 cpu 核心数 x 2。因此对于双核 cpu,它应该是 -j 4。但有些人建议编译线程数与核心数一样多。所以 -j 2 用于双核 cpu。

标签: bash makefile alias


【解决方案1】:

make 如果您只使用make -j,则不会自行查找内核数——相反,它会并行化到最大值。但是,您应该能够通过

grep -c "^processor" /proc/cpuinfo

或(根据 Azor-Ahai 的评论,如果在您的系统上可用)

nproc

因此:

make -j $(nproc)

有关详细信息,请参阅“如何How to obtain the number of CPUs/cores in Linux from the command line?”。另见GNU make: should the number of jobs equal the number of CPU cores in a system?

【讨论】:

  • 我认为这不是用户想要的答案……但是问题不是很清楚……
  • @DonCallisto:不,我很清楚这个问题:如果有 17 个内核,请使用 -j 17。刚才记错-j的语义了。
  • 现在你的答案很有意义......记得添加你创建别名的部分;-)
  • 这和使用nproc有什么不同吗?
  • @Azor-Ahai:我不这么认为,谢谢你告诉我nproc
猜你喜欢
  • 2019-09-17
  • 1970-01-01
  • 2014-06-14
  • 2010-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多