c - 信息 C5012 : loop not parallelized due to reason '1008'

标签 c visual-studio-2013 vectorization c99 sse2

我正在 x86_64 上试用 Visual Studio 2013 的自动矢量化器模式,我对以下内容感到有些惊讶。考虑原始代码:

static void rescale( double * __restrict out, const int * __restrict in, long n, const double intercept, const double slope )
{
    for( long i = 0; i < n; ++i )
        out[i] = slope * in[i] + intercept;
}

Visual Studio 返回它在这样一个天真的例子中失败了:

--- Analyzing function: rescale
c:\users\malat\autovec\vec.c(13) : info C5012: loop not parallelized due to reason '1008'

编译行在哪里(我现在只对SSE2感兴趣):

cl vec.c /O2 /Qpar /Qpar-report:2

查看文档:

导致:

内容如下:

The compiler detected that this loop does not perform enough work to warrant auto-parallelization.

有没有办法重写这个循环,以便正确触发自动矢量化器模式?

我未能使用简单的方法重写代码:

static void rescale( double * __restrict out, const double * __restrict in, long n, const double intercept, const double slope )
{
    for( long i = 0; i < n; ++i )
        out[i] = slope * in[i] + intercept;
}

在上述情况下,Visual Studio 仍然报告:

--- Analyzing function: rescale
c:\users\malat\autovec\vec.c(13) : info C5012: loop not parallelized due to reason '1008'

我应该如何重写我的初始代码以取悦 Visual Studio 2013 的自动矢量化器模式?我想用 64 位 double vector 做 a * b + c:SSE2

最佳答案

MSDN link you posted 底部附近的示例代码建议使用 hint_parallel pragma:

void code_1008()
{
    // Code 1008 is emitted when the compiler detects that
    // this loop does not perform enough work to warrant 
    // auto-parallelization.

    // You can resolve this by specifying the hint_parallel
    // pragma. CAUTION -- if the loop does not perform
    // enough work, parallelizing might cause a potentially 
    // large performance penalty.

    // #pragma loop(hint_parallel(0)) //  hint_parallel will force this through
    for (int i=0; i<1000; ++i)
    {
        A[i] = A[i] + 1;
    }
}

关于c - 信息 C5012 : loop not parallelized due to reason '1008' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43651706/

相关文章:

编译器说缺少声明;

将 IP 地址从 char * 转换为 uin32_t

visual-studio-2013 - EntityFramework.dll 中发生 System.Data.DataException 错误

c# - 如何让VS自动复制一个文件夹到构建目录?

r - 用于 R 中两个数据集之间计算的 for 循环矢量化

c - 字符串搜索不会打印整行

c - 递归函数将字符添加到 char 数组的末尾

asp.net-mvc - 将HDFS与Visual Studio 2013连接

python - 2D 和 3D 数组之间的相关系数 - NumPy/Python

c++ - SIMD/SSE : How to check that all vector elements are non-zero