algorithm - "make -jX"算法是什么

标签 algorithm makefile

假设您有一个表示 make 文件中定义的依赖关系的图表。什么(一个?)算法用于确定应该以什么顺序构建依赖关系以及什么是可并行化的(当使用 -jX 标志时)。

例如如果您有以下部门:

A: B C
B: D
C: D
D: 

“D”显然需要先构建,但构建完成后,B 和 C 可以并行构建,当它们都完成后,再构建 A。

最佳答案

通过使用make -d 打印调试信息,您可以准确地看到 make 使用的算法。对于您的示例(我添加了 echo 命令以实际导致某事发生):

$ make -r -d -j
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
 Considering target file `Makefile'.
  Looking for an implicit rule for `Makefile'.
  No implicit rule found for `Makefile'.
  Finished prerequisites of target file `Makefile'.
 No need to remake target `Makefile'.
Updating goal targets....
Considering target file `A'.
 File `A' does not exist.
  Considering target file `B'.
   File `B' does not exist.
    Considering target file `D'.
     File `D' does not exist.
     Finished prerequisites of target file `D'.
    Must remake target `D'.
Putting child 0x7fdae2c08110 (D) PID 71724 on the chain.
    Commands of `D' are being run.
   Finished prerequisites of target file `B'.
  The prerequisites of `B' are being made.
  Considering target file `C'.
   File `C' does not exist.
    Pruning file `D'.
   Finished prerequisites of target file `C'.
  The prerequisites of `C' are being made.
 Finished prerequisites of target file `A'.
The prerequisites of `A' are being made.
Live child 0x7fdae2c08110 (D) PID 71724 
D
Reaping winning child 0x7fdae2c08110 PID 71724 
Removing child 0x7fdae2c08110 PID 71724 from chain.
Considering target file `A'.
 File `A' does not exist.
  Considering target file `B'.
   File `B' does not exist.
    Considering target file `D'.
    File `D' was considered already.
   Finished prerequisites of target file `B'.
  Must remake target `B'.
Putting child 0x7fdae2c083c0 (B) PID 71729 on the chain.
  Commands of `B' are being run.
  Considering target file `C'.
   File `C' does not exist.
    Pruning file `D'.
   Finished prerequisites of target file `C'.
  Must remake target `C'.
Live child 0x7fdae2c083c0 (B) PID 71729 
Putting child 0x7fdae2c09020 (C) PID 71734 on the chain.
  Commands of `C' are being run.
 Finished prerequisites of target file `A'.
The prerequisites of `A' are being made.
Live child 0x7fdae2c09020 (C) PID 71734 
Live child 0x7fdae2c083c0 (B) PID 71729 
B
Reaping winning child 0x7fdae2c083c0 PID 71729 
Removing child 0x7fdae2c083c0 PID 71729 from chain.
Live child 0x7fdae2c09020 (C) PID 71734 
Considering target file `A'.
 File `A' does not exist.
  Considering target file `B'.
  File `B' was considered already.
  Considering target file `C'.
  Still updating file `C'.
 Finished prerequisites of target file `A'.
The prerequisites of `A' are being made.
Live child 0x7fdae2c09020 (C) PID 71734 
C
Reaping winning child 0x7fdae2c09020 PID 71734 
Removing child 0x7fdae2c09020 PID 71734 from chain.
Considering target file `A'.
 File `A' does not exist.
  Considering target file `B'.
  File `B' was considered already.
  Considering target file `C'.
  File `C' was considered already.
 Finished prerequisites of target file `A'.
Must remake target `A'.
Putting child 0x7fdae2c090c0 (A) PID 71739 on the chain.
Commands of `A' are being run.
Live child 0x7fdae2c090c0 (A) PID 71739 
A
Reaping winning child 0x7fdae2c090c0 PID 71739 
Removing child 0x7fdae2c090c0 PID 71739 from chain.
Considering target file `A'.
File `A' was considered already.

同时注意这两行:

Live child 0x7fdae2c09020 (C) PID 71734 
Live child 0x7fdae2c083c0 (B) PID 71729 

同时显示 BC 配方。

关于algorithm - "make -jX"算法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17286460/

相关文章:

visual-studio-2010 - 在Visual Studio 2010上使用.mak文件

c - 在 Eclipse 上导入的 Makefile 项目 : sources not listed and unresolved inclusions

c++ - 构建 websocket++ 时为 "src/common.hpp:52:32: fatal error: boost/shared_ptr.hpp: No such file or directory"

makefile - GNU make : Override variable based on target

algorithm - 索引算法来开发像谷歌桌面搜索这样的应用程序?

algorithm - 不使用/或 * 运算符的整数除法

algorithm - 获取二维数组中的相邻元素?

MySQL - 索引会加速我的搜索查询吗?

javascript - 一组随机数

c - 生成文件的自动操作