我需要组成 4 个团队,每个团队有 4 个线程,每个团队都有连续的处理器。
我期待的结果是,例如:
Team 0 Thread 0 Processor: 0
Team 0 Thread 1 Processor: 1
Team 0 Thread 2 Processor: 2
Team 0 Thread 3 Processor: 3
Team 1 Thread 0 Processor: 4
Team 1 Thread 1 Processor: 5
Team 1 Thread 2 Processor: 6
Team 1 Thread 3 Processor: 7
Team 2 Thread 0 Processor: 8
Team 2 Thread 1 Processor: 9
Team 2 Thread 2 Processor: 10
Team 2 Thread 3 Processor: 11
Team 3 Thread 0 Processor: 12
Team 3 Thread 1 Processor: 13
Team 3 Thread 2 Processor: 14
Team 3 Thread 3 Processor: 15
我可以使用 GOMP_CPU_AFFINITY 变量在 GCC 中处理处理器关联。
我在用着:
#pragma omp parallel num_threads(4)
两次以获得 2 个分叉级别。
目前我在 GOMP_CPU_AFFINITY 有这个订单:
0 4 8 12 1 2 3 5 6 7 9 10 11 13 14 15
所以第一个叉子,“父亲叉子”,得到:
Team 0 Thread 0 Processor: 0
Team 1 Thread 0 Processor: 4
Team 2 Thread 0 Processor: 8
Team 3 Thread 0 Processor: 12
我遇到的问题是第二组叉子没有任何顺序,例如我可能会遇到这种情况(我正在使用#pragma omp atomic,所以只有一个“父亲”可以随时要求更多处理器) :
Team 0 Thread 0 Processor: 0
Team 0 Thread 1 Processor: 5
Team 0 Thread 2 Processor: 6
Team 0 Thread 3 Processor: 7
Team 1 Thread 0 Processor: 4
Team 1 Thread 1 Processor: 13
Team 1 Thread 2 Processor: 14
Team 1 Thread 3 Processor: 15
Team 2 Thread 0 Processor: 8
Team 2 Thread 1 Processor: 1
Team 2 Thread 2 Processor: 2
Team 2 Thread 3 Processor: 3
Team 3 Thread 0 Processor: 12
Team 3 Thread 1 Processor: 9
Team 3 Thread 2 Processor: 10
Team 3 Thread 3 Processor: 11
问题是:有没有办法让第二次请愿按顺序进行?
我想我必须用锁或其他东西做一些同步方法......
提前致谢!
- 哈维尔