gpt4 book ai didi

c - OpenMP 中循环的矢量化

转载 作者:太空宇宙 更新时间:2023-11-04 07:35:14 25 4
gpt4 key购买 nike

我正在用 C 编写一个程序(一个二维泊松求解器),我正在使用 openMP 来加速一个大的 for 循环。我观察到的是,在 openMP 并行 block 内,即使在我包含 #pragma always vector 指令的情况下,for 循环也未矢量化。对于编译,我使用的是 pathscale 编译器。

我要矢量化的代码如下所示:

  #pragma omp parallel shared(in, out, lambda,dim,C) private(k)
{
#pragma omp for schedule(guided,dim/nthreads) nowait
for(k = 0;k < dim; k++){
in[k] = C*out[k]*lambda[k];
}
}

其中 out、lambda 和 in 是 double 组。

但即使我包含#pragma always vector,编译器的回答也是:

 warning: ignoring #pragma always vector

你知道这是否有任何解决方法吗?

谢谢。

最佳答案

我浏览了 the User Guide for the PathScale compiler , 并且既没有找到 #pragma always 也没有找到 #pragma vector。所以我认为编译器只是告诉你它不识别这个 pragma,并忽略它。

然而,在第 7.4.5 节中,我发现以下选项可以帮助您进行矢量化:

Vectorization of user code ... is controlled by the flag -LNO:simd[=(0|1|2)], which enables or disables inner loop vectorization. 0 turns off the vectorizer, 1 (the default) causes the compiler to vectorize only if it can determine that there is no undesirable performance impact due to sub-optimal alignment, and 2 will vectorize without any constraints (this is the most aggressive).

-LNO:simd_verbose=ON prints vectorizer information (from vectorizing user code) to stdout.

作为旁注(猜测您可以从哪里获取 #pragma always vector),Intel's compiler has #pragma vector always 是 pragma 的一个可能参数。但是 pragma 通常是特定于编译器的,除了少数几个由多个供应商支持的扩展(OpenMP 就是其中之一)。

关于c - OpenMP 中循环的矢量化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9642954/

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