知识卡片
并行循环下标是各迭代私有变量
并行循环的下标在每次迭代中各有独立实例,即使名称相同,也不是竞争的共享地址。
相反,多个迭代写同一结果元素仍会产生竞争。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 第26章 并行算法 · 查看原书依据
Index variables of parallel for loops, such as i in line 1 and j in line 2, do not cause races between iterations. Conceptually, each iteration of the loop creates an independent variable to hold the index of that iteration during that iteration’s execution of the loop body. Even if two parallel iterations both access the same index variable, they really are accessing different variable instances—hence different memory locations—and no race occurs.
参考来源
- 位置:《算法导论(第4版)》第26章《并行算法》(OEBPS/chapter026.xhtml,文本字符[45000,50000))。
- 结论依据:第26章错误示例 P-MAT-VEC-WRONG 第1–3行:并行 for 的索引变量按迭代私有;第3行并发更新同一个 y_i 才构成确定性竞争。
- 原始内容:Index variables of parallel for loops, such as i in line 1 and j in line 2, do not cause races between iterations. Conceptually, each iteration of the loop creates an independent variable to hold the index of that iteration during that iteration’s execution of the loop body. Even if two parallel iterations both access the same index variable, they really are accessing different variable instances—hence different memory locations—and no race occurs.