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 循环,是否会再次并行化 for 循环,或者每个线程都会执行自己的 for 循环?
T sum; #pragma omp parallel { #pragma omp for reduction(+: sum) for (;;) { T priv_var; sum += priv_var; } }
是的,此代码将导致 OpenMP 在for由该parallel区域产生的线程之间并行化循环。但是,我相信您当前的for声明对于 OpenMP 并行化无效。您需要显式提供整数循环变量、开始和结束以及增量表达式。
for
parallel
实际上,您的代码将等效于带有#pragma omp parallel for reduction(+: sum).
#pragma omp parallel for reduction(+: sum)
有关 MDSN 的更多信息