Compiling Cilk plus on Ubuntu 12.04 using gcc 4.7

Compiling Cilk plus on Ubuntu 12.04 using gcc 4.7


I am having trouble building Cilk plus (cilkplus-rtl-001857.tgz) on Ubuntu 12.04. The version of gcc and the error are below:

$ gcc --version
gcc (Ubuntu/Linaro 4.7.0-7ubuntu3) 4.7.0
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO


runtime/symbol_test.c: In function 'main':
runtime/symbol_test.c:50:5: error: unknown type name '_Cilk_spawn'
runtime/symbol_test.c:50:17: error: conflicting types for 'foo'
runtime/symbol_test.c:44:6: note: previous definition of 'foo' was here
runtime/symbol_test.c:51:5: warning: implicit declaration of function '_Cilk_for' [-Wimplicit-function-declaration]
runtime/symbol_test.c:51:21: error: expected ')' before ';' token
runtime/symbol_test.c:52:9: error: expected ';' before 'foo'
runtime/symbol_test.c:53:21: error: expected ')' before ';' token
runtime/symbol_test.c:54:9: error: expected ';' before 'foo'
make: *** [symbol_test.lo] Error 1

I followed the steps given in README.txt. Is there anything else I have to do to get this installed?


14 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

Hi Pranith,
     Did you check out the CilkPlus gcc source from GNU? That is the only way to build the runtime. Here is a tutorial I wrote up a while back. When you check out the compiler and built it, it will also build the runtime for you. You do not need to do that as a seperate step. Please let me know if you need additional details:

How to Download, Build and Install Cilkplus GCC on Linux. Prerequisites

You will need the following packages to build GCC:

  • Source packages. Note that the links below are for the versions needed to build the initial release of the cilkplus GCC branch. Newer versions may need to be used with future versions of the compiler.
    • GNU Multiprecision Arithmetic Library (GMP) for arbitrary precision arithmetic: ( Download the latest version and unpack the compressed tar file and move the directory to $HOME/gmp .
    • GNU MPFR Library multiple-precision floating-point computations with correct rounding: ( Unpack the compressed tar file and move the directory to $HOME/mpfr .
    • GNU MPC Library for arithmetic using complex numbers: ( Download the latest version and unpack the compressed tar file. Move the unpacked directory to $HOME/mpc
  • In addition to the sources above, you will also need the following tools installed in your machine
    • flex or lex - Lexical analyzer
    • bison or Yacc - Parser generator
    • Make utility (example gmake) to automatically create executables
    • GCC/G++ Compiler (version 4.4 or above) with the appropriate binary utilities
    • GNU AutoGen utility - Automatic program generator
    • SVN or GIT source control packages
  • Diskspace: You will need approximately 2 GB of diskspace to hold the sources, executables and libraries. Along with this, you will also require ~3 GB of diskspace to hold the temporary files.
  • Time: This process is a bit time-consuming and so please have ~4-5 hours  in-hand to complete the process. The most time consuming of all is step 6. This step is not interactive and so you can let this step run overnight if you wish.

Building the GCC C and C++ compilers

  1. Cilkplus GCC is available as a development branch in the GCC source-tree. The development branch is called "cilkplus." They can be downloaded using GIT or SVN source-control systems. If you are a beginner to source-control, I would recommend you use SVN. I am making an assumption that you are currently in your $HOME directory. 
    • To use SVN, please type the following  in your command in your command prompt:
      • svn co cilkplus-gcc
    • If you are choosing to use GIT, please type the following commands in your command prompt. Please note that this step can take anywhere from 10-30 minutes.
      • git clone cilkplus-gcc
      • cd cilkplus-gcc
      • git checkout -b my_cilkplus_branch origin/cilkplus
      • cd ..
  2. After step 1, the sources should be saved in a directory called $HOME/cilkplus-gcc. The final compiler executables and the appropriate libraries will be stored in $HOME/cilkplus-install .
  3. Move the gmp, mpc and mpfr directories from $HOME/ to the $HOME/cilkplus-gcc/ directory.
  4. Create a new directory called "b-gcc" under $HOME/ . This directory will hold all the object files. You may delete this directory after the successful completion of all the steps in this tutorial.
  5. Go to the b-gcc directory and type the following command:

    $HOME/cilkplus-gcc/configure --prefix=$HOME/cilkplus-install --enable-languages="c,c++" 

    The above command will configure the compiler makefiles to set the install directory to be $HOME/cilkplus-install and build just the C and C++ compilers.

  6. Type make in the same directory. This command will build the compiler sources.  This will probably take quite a while.
  7. Type make install. This command will copy the compiler executables and the required libraries to the install directory.

The compilers (g++ and gcc) should now be in the $HOME/cilkplus-install/bin directory.

Using the GCC compilers with the Intel® Cilk™ Plus extensions

To use the GCC Cilk Plus compiler, it needs to be in your PATH and the libraries need to be in your LIBRARY_PATH and LD_LIBRARY_PATH. The following commands can be used (in a BASH Shell) to accomplish this:

export PATH=$HOME/cilkplus-install/bin:$PATH
export LD_LIBRARY_PATH=$HOME/cilkplus-install/lib
export LIBRARY_PATH=$HOME/cilkplus-install/lib

Building a Cilk Plus application with the GCC compilers requires explicitly linking with libcilkrts, libdl and libpthread. For example:

$HOME/cilkplus-install/bin/gcc -ldl -lcilkrts
$HOME/cilkplus-install/bin/g++ -ldl -lcilkrts

I did not install gcc from the GNU source. I followed your guide and was able to compile it successfully!!Only additions to the above is I had to do:

$ sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64

for the compile to complete succesfully. Thanks a ton!

Glad to hear it is went smoothly!

-Balaji V. Iyer.

i followed the above procedure,after completion of that procedure, i tried to compile the following program with the following command
# /home/cilkplus-install/bin/gcc cilkexample.c -ldl -lcilkrts

#include <stdio.h>
#include <cilk/cilk.h>
void main()
printf("Helllo World \n");

output after compilation :
/usr/local/include/cilk/cilk.h:42:25: fatal error: cilk-sysdep.h: No such file or directory
#include <cilk-sysdep.h>
compilation terminated.

can anyone help me thanks for the help

What does your copy of cilk/cilk.h look like?

The copy of cilk.h that I have only contains 3 macros in it, defined for convenience.

#define cilk_spawn _Cilk_spawn
#define cilk_sync _Cilk_sync
#define cilk_for _Cilk_for

I'm not sure where the attempt to include cilk-sysdep.h is coming from...?

EDIT: Also, which files were you trying to include with the "#include"' statements?

I've modified Sudheer's message so the angle brackets are displayed instead of being interpreted as HTML tags.

- Barry

I did a quick check. I believe you may have a copy of MIT Cilk (cilk-5.4.6) installed, and you are including "cilk.h" from MIT Cilk.
The "cilk.h" for MIT Cilk has an #include of cilk-sysdep.h on line 42.

To use Cilk Plus, you need to make sure the Cilk Plus directories are first in the appropriate include paths. It seems that there are conflicts in having both installed at the same time, since both systems have their own files named "cilk.h".



thanks for the help, i removed the cilk folder in the usr/local/lib, after this compiled successfully but when i am running the program using the following command
/home/cilkplus-install/bin/gcc -ldl -lcilkrts cilkexample.c

int Fibonacci_Parallel(int n) {
return n;
else {
int x=0;
_Cilk_spawn x=Fibonacci_Parallel(n-1);
int y=Fibonacci_Parallel(n-2);
return x+y;
void main()
printf("Helllo World \n");
int i=0;
int j=0;
execution command # ./a.out
output :
./a.out: error while loading shared libraries: cannot open shared object file: No such file or directory

when i removed the lcilkrts in the compilation command it compiled successful and running, but it is taking only one core for the computation.
can u tell me detailed process how to run the programs.

Thanks for the help

The GCC compiler does not enable Cilk Plus by default. You need to enable it using the "-fcilkplus" option as well as specifying the -lcilkrts option to link against the Cilk Plus runtime. If you don't specify this, you'll get the serialization of your application.

Once you do build the program, must be in the LD_LIBRARY_PATH.

- Barry

i complied the program by using the command
compilation :- /home/cilkplus-install/bin/gcc -ldl -lcilkrts -fcilkplus cilkexample.c
execution :- ./a.out
it is running successfully, but how can i ensure that the program taking all available cores for the computation
i checked the system-moniter, when i am running the program it is taking only one core for the execution

thanks for the help

A couple thoughts that might help:

1. One way to debug this problem is using is to query the number of workers that Cilk thinks it has, and print it out.

#include "cilk/cilk_api.h" // I really mean "<" and ">" instead of the quotes, but the browser is interpreting this text as html...

int P = __cilkrts_get_nworkers();
printf("P = %d\n", P);

Hopefully, P is greater than 1 on your system.

2. The number of workers used to execute a program can set explicitly by setting the "CILK_NWORKERS" environment variable. For example:


3. What input size are specifying to Fibonacci_Parallel? As written above, the program above does not look like it should finish (at least in any reasonable amount of time), since the running time of the recursive calculation of Fibonacci numbers is exponential in the size of its input n.

Finally, for inputs n < 20 or 25, you might not see much speedup on such a "fib" calculation, since the computation completes fairly quickly even on one worker. With n somewhere in the range of 30 to 40, I have seen reasonable speedups. Larger values of n have more parallelism.
Tests for values n >= 44 tend to take long enough that I usually don't run them.


can you suggest any references for cilkplus

Thanks for the help

We have a basic tutorial on Cilk Plus on our website:

In the documentation section, there are also links to more information about Cilk Plus in the Intel compiler under "Getting Started" or "Reference Manual". The concepts described here should generally carry over directly to the GCC version as well.

Finally, you can find links to a number of projects and research papers online that refer to "Cilk". These links typically refer to one or more versions of Cilk. Unfortunately, some care is required to figure out whether a given link applies to Cilk Plus, as the naming of various projects has not always been perfectly consistent as Cilk has evolved. Often, many of the high-level concepts are consistent between different versions of Cilk, but important implementation details can vary.

A brief history of Cilk can be found at:

Hope that helps,


Leave a Comment

Please sign in to add a comment. Not a member? Join today