Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
说我有一个循环
for(int i = 0; i < 1000; i++){ sum += i; }
如果我使用 OpenMP 来加速它,这个 for 循环如何映射到 4 个不同的内核?
我知道它使用 fork 和 join,我的意思是 i=0 代表核心 0,i=1 代表核心 1 等还是 i=0 代表核心 0,i=249 代表核心 1,i = 499 代表核心 2 等等.
谢谢,
鲍勃
根据此演示文稿,它取决于编译器实现而不是 OpenMP 规范,但编译器可能会将 i=0 用于核心 0,i=249 用于核心 1,等等。
还要确保您是 的减少变量sum,否则您的示例中有竞争条件。
sum