gpt4 book ai didi

c - 用于区域线程关联的 OpenMP 并行

转载 作者:行者123 更新时间:2023-12-04 05:12:30 27 4
gpt4 key购买 nike

假设我有以下 OpenMP 区域:

omp_set_num_threads(3);
#pragma omp parallel for
{
//start
...
//somewhere in the middle
...
//end
}

假设我有 8 核系统。例如,在“开始”之后,假设线程 0 在核心 4 上运行,线程 1 在核心 5 上运行,线程 2 在核心 6 上运行。线程迁移从“结束”之前的“中间某处”是否可能他们各自的核心是在“开始”之后分配的? IE。是否有可能在“开始”之后将线程 0-2 分配给核心 4-5,而“中间某处”线程说分别迁移到核心 5-7?甚至有可能线程可能驻留在核心 0-2 上的“结束”之前?谢谢。

最佳答案

据我所知,OpenMP 3.1 规范没有提供任何重新绑定(bind)线程的方法。

事实上,对线程绑定(bind)进行一些控制的唯一方法是通过 OMP_PROC_BIND环境变量:

The OMP_PROC_BIND environment variable sets the value of the global bind-var ICV. The value of this environment variable must be true or false. If the environment variable is set to true, the execution environment should not move OpenMP threads between processors. If the environment variable is set to false, the execution environment may move OpenMP threads between processors. The behavior of the program is implementation defined if the value of OMP_PROC_BIND is neither true nor false.



OpenMP 4.0 草案扩展了 OMP_PROC_BIND 的可能值。并添加 OMP_PLACES环境变量,它允许选择线程如何绑定(bind)到资源。尽管如此,仍然没有重新绑定(bind)线程的标准方法。

如果这种行为对你来说是绝对必要的,你可以考虑使用 hwloc图书馆,尤其是 CPU binding部分。

关于c - 用于区域线程关联的 OpenMP 并行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14720642/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com