1

I am trying to test the following code in 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;
}

I am getting the following error. It seems that g++ command can detect cilk plus but cannot compile somehow.

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++) 
                    ^
aghost
  • 235
  • 2
  • 12
  • My guess is that `cilk_for` is a macro wrapping a normal `for` loop, which means you need to include the header file the macro is defined in. I suggest you read [the `cilk_for` reference](https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-ABF330B0-FEDA-43CD-9393-48CD6A43063C.htm). – Some programmer dude Jun 25 '15 at 18:58
  • 1
    I have tried #include but does not work. – aghost Jun 25 '15 at 18:59
  • What problems do you get if you include the header file? The same? Something else? And you should really move the libraries to the end of the command line, after you list the source file (see e.g. [this old answer of mine](http://stackoverflow.com/questions/13784434/gcc-use-openssls-sha256-functions/13784484#13784484)). – Some programmer dude Jun 25 '15 at 19:01
  • @AnirbanGhosh Joachim is right. You need to include `cilk.h` file. Update the error section when you include cilk.h file – JamesWebbTelescopeAlien Jun 25 '15 at 19:03
  • I have updated the code and the error output. – aghost Jun 25 '15 at 19:06
  • [Reading more](https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-2738DAA6-469E-43BE-9CD6-F3C8E0A6B4C3.htm) of the [documentation](https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/index.htm) makes me wonder if Cilk can be used with any other than the Intel compiler ICC? – Some programmer dude Jun 25 '15 at 19:11
  • 1
    For example, the `cilk_for` reference linked before says that the ***keyword*** is `_Cilk_for`, and since symbol names starting with an underscore followed by a capital letter is reserved for the implementation, it seems to me it really *is* a keyword and an extension to the base C and C++ languages specific for the Intel compiler. – Some programmer dude Jun 25 '15 at 19:14
  • Indeed, see https://software.intel.com/en-us/c-compilers. It says that in GCC 4.9 the keyword is not supported. – aghost Jun 25 '15 at 19:23

1 Answers1

2

Your g++ command is incorrect. It should be

g++ test_cilk.cpp -fcilkplus -lcilkrts
                   ^
  • Thank you. But I am sorry I am getting the same error. – aghost Jun 29 '15 at 19:23
  • 1
    The default version of g++ in Ubuntu 15.04 is g++ 4.9, which doesn't support cilk_for. It's a known limitation. Make sure you're running g++ 5.0 or later. What does the following command display? "g++ --version" – Barry Tannenbaum - Intel Jun 30 '15 at 19:59
  • Yes you are correct. The compiler version is indeed 4.9. I will try to install version 5.0. Thank you very much for the information. – aghost Jul 01 '15 at 00:22