"无效控股predicate"使用OpenMP编译器错误 [英] "invalid controlling predicate" compiler error using OpenMP

查看:859
本文介绍了"无效控股predicate"使用OpenMP编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个基本的素数检查的基础上的ç - 确定一个数是素,但采用的OpenMP。

I'm creating a basic prime number checker, based on C - determine if a number is prime , but utilising OpenMP.

int isPrime(int value)
{
    omp_set_num_threads(4);

    #pragma omp parallel for 
    for( int j = 2;  j * j <= value; j++)
    {
    if ( value % j == 0) return 0;
    }
    return value;
}

在使用的 -fopenmp 的,GCC 4.7.2版本的示数,说明编译无效控制predicate 关于for循环

When compiling with -fopenmp, GCC version 4.7.2 is erroring, stating invalid controlling predicate with respect to the for loop.

它看起来像这样的错误是由法官在平方循环引起的。有没有一种方法,我可以解决此,仍然实现了从算法所需的输出?

It looks like this error is caused by the j squared in the for loop. Is there a way I can work around this and still achieve the desired output from the algorithm?

推荐答案

收益是不允许的,因为它会导致大括号之前退出循环中。

return is not allowed inside the loop as it will cause exit before the curly braces.

请注意下面给出的定义:

Note the definition given below :

从OpenMP的V2.5规范,1.2.2 OpenMP的语言术语,P2:17 -

From the OpenMP V2.5 spec, 1.2.2 OpenMP language terminology, p2:17-

结构块 - 对于C / C ++,一个可执行语句,可能
  化合物,在顶部在一个单一的输入和单一的出口
  底部。

structured block - For C/C++, an executable statement, possibly compound, with a single entry at the top and a single exit at the bottom.

一个结构化块用开启动{和闭幕结束} 。在收益包含这些括号之内,所以这个方案也违反了一个结构化块OpenMP的定义,因为它有两个出口(一个在回归,一个在通过支架出口)

A structured block starts with the open { and ends with the closing }. The return is contained within these braces, so this program also violates the OpenMP definition for a structured block, because it has two exits (one at the return and one at the exit through the brace)

的OpenMP放在哪些循环可以拧以下五个限制:

OpenMP places the following five restrictions on which loops can be threaded:


  • 循环变量的类型必须为有符号整数。无符号整数,
    如DWORD的,将无法工作。

  • 比较操作必须在形式loop_variable &LT; &LT; = &GT;
    &GT; = loop_invariant_integer

  • 的for循环的第三个前pression或增量部分必须
    任一整数加法或整数减法和由环
    不变的值。

  • 如果比较操作是&LT; &LT; = ,循环变量必须
    递增每次迭代,反之,如果比较
    操作&GT; &GT; = ,循环变量必须减小每
    迭代。

  • 循环必须是一个基本块,这意味着没有从里面跳
    循环到外部允许与出口除外
    声明,终止整个应用程序。如果语句
    后藤或破裂时,它们必须在循环中跳出,不在外面
    它。这同样适用于异常处理;异常必须被捕获
    在循环中。

  • The loop variable must be of type signed integer. Unsigned integers, such as DWORD's, will not work.
  • The comparison operation must be in the form loop_variable <, <=, >, or >= loop_invariant_integer
  • The third expression or increment portion of the for loop must be either integer addition or integer subtraction and by a loop invariant value.
  • If the comparison operation is < or <=, the loop variable must increment on every iteration, and conversely, if the comparison operation is > or >=, the loop variable must decrement on every iteration.
  • The loop must be a basic block, meaning no jumps from the inside of the loop to the outside are permitted with the exception of the exit statement, which terminates the whole application. If the statements goto or break are used, they must jump within the loop, not outside it. The same goes for exception handling; exceptions must be caught within the loop.

这篇关于&QUOT;无效控股predicate&QUOT;使用OpenMP编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆