【问题标题】:Cilk Plus in UbuntuUbuntu 中的 Cilk Plus
【发布时间】:2015-06-25 18:54:38
【问题描述】:

我正在尝试在 Ubuntu 15.04 中测试以下代码。

#include <iostream>
#include <cilk/cilk.h>

using namespace std;

int main() 
{
    cilk_for(int x=0; x<10; x++) 
    {
        cout << x << endl;
    }
    return 0;
}

我收到以下错误。似乎 g++ 命令可以检测到 cilk plus 但无法以某种方式编译。

anirban@anirban-XPS-8500:~$ g++ test_cilk.cpp -lcilkplus -lcilkrts
test_cilk.cpp: In function ‘int main()’:
test_cilk.cpp:8:11: error: expected primary-expression before ‘int’
  cilk_for(int x=0; x<10; x++) 
           ^
test_cilk.cpp:8:20: error: ‘x’ was not declared in this scope
  cilk_for(int x=0; x<10; x++) 
                    ^

【问题讨论】:

  • 我的猜测是cilk_for 是一个包含普通for 循环的宏,这意味着您需要包含定义宏的头文件。我建议您阅读the cilk_for reference。
  • 我尝试过#include 但不起作用。
  • 如果包含头文件会出现什么问题?相同?还有什么?在列出源文件之后,您应该真正将库移动到命令行的末尾(参见例如this old answer of mine)。
  • @AnirbanGhosh Joachim 是对的。您需要包含cilk.h 文件。包含 cilk.h 文件时更新错误部分
  • 例如,之前链接的cilk_for 引用表明关键字 是_Cilk_for,并且因为符号名称以下划线开头大写字母是为实现保留的,在我看来,它确实是是一个关键字,是英特尔编译器专用的基本 C 和 C++ 语言的扩展。

标签: c++ ubuntu cilk-plus


【解决方案1】:

您的 g++ 命令不正确。应该是

g++ test_cilk.cpp -fcilkplus -lcilkrts
                   ^

【讨论】:

  • 谢谢。但很抱歉,我遇到了同样的错误。
  • Ubuntu 15.04中g++的默认版本是g++ 4.9,不支持cilk_for。这是一个已知的限制。确保您运行的是 g++ 5.0 或更高版本。以下命令显示什么? "g++ --version"
  • 是的,你是对的。编译器版本确实是4.9。我将尝试安装 5.0 版。非常感谢您提供的信息。
猜你喜欢
  • 2016-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多