How to Download, Build, and Install Cilk Plus GCC on Linux

Prerequisites

  • 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 3 GB of diskspace to hold the sources, executables and libraries. Along with this, you will also require ~5 GB of diskspace to hold the temporary files.
  • Time: ~4-5 hours  are required to complete the process.
    • The speed of the fetch will depend on your internet connection.
    • The build (step 5) is time consuming, but it is not interactive. You can let this step run overnight if you wish.

Building the GCC C and C++ compilers

Note: The following instruction assume that you are starting in your $HOME directory.

  1. Fetch the source for the GCC compilers with the Cilk Plus extension. There are two branches of GCC which contain the Cilk Plus extension:
    1. cilkplus - This branch is based on the GCC 4.9 compiler which is still under active development. The GCC sources for this branch can be downloaded using the GIT or SVN source control systems, or you can download a snapshot. A snapshot is probably easiest for a beginner.
      1. Using SVN: To download the sources using SVN from this branch, use the following command:
          svn co http://gcc.gnu.org/svn/gcc/branches/cilkplus cilkplus-gcc
         
      2. Using GIT: To download the sources using GIT from this branch, use the following commands:
          git clone http://gcc.gnu.org/git/gcc.git cilkplus-gcc
        cd cilkplus-gcc
        git checkout -b my_cilkplus_branch origin/cilkplus
        cd ..

         
      3. Using a snapshot: A snapshot is a compressed tarfile of the sources for a specific version of the branch. To download a snapshot of the cilkplus branch, go to http://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/cilkplus and click the snapshot link on the top line of the list of checkins. It will take a few moments for the server to fetch the sources and build a compressed tarfile. Once the compressed tarfile has downloaded, unpack it using the following commands:
          tar -xf <downloaded-file>
        mv <downloaded-file-name> cilkplus-gcc

         
    2. cilkplus-4_8-branch - This branch is based on the GCC 4.8 compiler which is the current, stable release. The cilkplus-4_8-branch is only available using SVN or snapshots. A snapshot is probably easier for a beginner.
      1. Using SVN: To download the sources from this branch, use the following command:
          svn co http://gcc.gnu.org/svn/gcc/branches/cilkplus-4_8-branch/ cilkplus-gcc
         
      2. Using a snapshot: A snapshot is a compressed tarfile of the sources for a specific version of the branch. To download a snapshot of the cilkplus branch, go to http://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/cilkplus-4_8-branch and click the snapshot link on the top line of the list of checkins. It will take a few moments for the server to fetch the sources and build a compressed tarfile. Once the compressed tarfile has downloaded, unpack it using the following commands:
          tar -xf <downloaded-file>
        mv <downloaded-file-name> cilkplus-gcc

    The compiler sources for the branch of your choice should now be in the directory $HOME/cilkplus-gcc.

  2. cd into your cilkplus-gcc directory and execute the following command to fetch the prerequisite libraries:

    ./contrib/download_prerequisites

  3. Create a new directory called "b-gcc" under $HOME/ . This directory will hold all the object files. You may delete this directory after building the compiler.

  4. Go to the b-gcc directory and type the following command to configure the compiler makefiles to set the install directory to be $HOME/cilkplus-install and build just the C and C++ compilers:

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

  5. Type make in the same directory. This command will build the compiler sources and will probably take quite a while.

  6. Type make install. This command will copy the compiler executables and the required libraries to the install directory.

Using the GCC compilers with the Cilk™ Plus extensions

When the build above completes, the files will be in following locations:

  • The g++ and gcc compilers built above should now be in $HOME/cilkplus-install/bin
  • The Cilk Plus include files are in $HOME/cilkplus-install/include/cilk
  • The Cilk Plus shared object files are in $HOME/cilkplus-install/lib (for the x86 architecture) and $HOME/cilkplus-install/lib64 (for the Intel64 architecture)

To use the compiler you just built, issue the following commands on a 32-bit OS:

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

To use the compiler you just built, issue the following commands on a 64-bit OS.  The compiler and loader will automatically choose the correct (32-bit or 64-bit) files:

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

Building a Cilk Plus application with the GCC compilers requires explicitly enabling the Cilk Plus extension and linking with libcilkrts. For example:

$HOME/cilkplus-install/bin/gcc -fcilkplus -lcilkrts <OTHER_FLAGS> <SRC_FILES>
$HOME/cilkplus-install/bin/g++ -fcilkplus -lcilkrts <OTHER_FLAGS> <SRC_FILES>