info C5012:循环未并行化由于原因' 1008'

时间:2017-04-27 07:50:05

标签: 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

查看文档:

导致:

其中读作:

  

编译器检测到此循环没有执行足够的工作   保证自动并行化。

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

我没有使用一种简单的方法重写代码:

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位双精度矢量{SSER2

进行a * b + c

2 个答案:

答案 0 :(得分:1)

您给出的MSDN的第二个链接包含如何强制编译器对循环进行矢量化的示例。

// 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;
}

答案 1 :(得分:1)

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;
    }
}