并行算法讲述的是怎么用多处理器来解决问题。设计一个并行算法包括以下某些步骤:
- Identifying portions of the work that can be performed concurrently.
- Mapping the concurrent pieces of work onto multiple processes running in parallel.
- Distributing the input, output, and intermediate data associated with the program.
- Managing accesses to data shared by multiple processors.
- Synchronizing the processors at various stages of the parallel program execution.
这里的讨论不考虑自动并行化工具和编译器的作用,这里讨论的并行算法是程序员的责任。
任务依赖图( taskdependency graph):有向无环图
粒度(granularity)
1. 细粒度(fine-grained)将任务分解成大量细小的任务。
2. 粗粒度(coarse-grained)少量的大任务。
并发度(degree of concurrency):任一时刻可同时执行的最大任务数称为最大并发度。并发度依赖于任务图的形状,同样的粒度(基于同样的分解)不能保证同样的并发度。
平均并发度:总工作量与关键路径长度(任何一对起始节点与终止节点之间的最长有向路径)的比就是平均并发度。较短的关键路径有利于达到较高的并发度。
我们不能获得无限的加速比(串行运行时间与并行运行时间的比率):
1. 有限的粒度和并发度。
2. 不同处理器上任务之间的交互(某个任务的输出是另一个任务的输入,访问同一个变量副本)。