View on GitHub

Cilk Plus/LLVM

An implementation of the Intel® Cilk™ Plus C/C++ language extensions in LLVM

Intel® Cilk™ Plus is an extension to the C and C++ languages to support data and task parallelism. It is one of the easiest, quickest way to harness the power of both multicore and vector processing. Visit cilkplus.org for details.

This project implements the Intel® Cilk™ Plus language extensions in the Clang frontend for LLVM. There are two other implementations available. A commercial version of Cilk Plus is available as part of the Intel® C++ Composer XE compiler. There is also an open source version available in the "cilkplus" branch of the GCC C/C++ compiler. More information is available on cilkplus.org.

News

February 4, 2016

$ cd where-you-want-llvm-to-live
$ git clone -b cilkplus https://github.com/cilkplus/llvm llvm
$ git clone -b cilkplus https://github.com/cilkplus/clang llvm/tools/clang
$ git clone -b cilkplus https://github.com/cilkplus/compiler-rt llvm/projects/compiler-rt

The source code structure follows Clang/LLVM: http://llvm.org/docs/GettingStarted.html.

Building

The recommended way to build Cilk Plus/LLVM is using CMake. Detailed instructions on how to build Clang/LLVM/Compiler-rt with CMake can be found in the following page: http://llvm.org/docs/CMake.html. In the following command, make sure to replace /install/prefix with the location where you would like to install the binaries.

$ cd llvm
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DINTEL_SPECIFIC_CILKPLUS=1 -DCMAKE_INSTALL_PREFIX=/install/prefix -DCMAKE_BUILD_TYPE=Release \
        -DLLVM_TARGETS_TO_BUILD=X86 ..
$ make && make install

The most important thing here is -DINTEL_SPECIFIC_CILKPLUS=1. Without this define you won't be able to build anything (later we'll change it).

Attention: To run (rather than just compile) code you need to get or build an Intel Cilk Runtime.
You can build the runtime using our new script where-you-want-llvm-to-live/llvm/_build.sh. This script intends to help you to configure and build the whole stuff related to the compiler on Linux.

Mac OS X

The basic steps are the same as above. However, on Mac OS X it is recommended to build with the Clang compiler shipped with the OS. Add the following definitions to the cmake command above.

-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++

Windows

Follow instructions described on Clang web site:
  • Use something like -G "Visual Studio 12" to generate MS Studio project files
  • Use Studio to open file "LLVM.sln" and build project "clang"
  • Attention: this is preliminary solution for Windows and it will be updated soon.

    Downloading

    Instead of building from sources you're able simply to download the precompiled image of our compiler related to your OS: Linux or Mac.

    Attention: these images were not updated for the latest sources. We're planning to updatem the images soon and to add Windows image as well.

    Using

    To use the newly installed compiler, add the following to your environment. On Mac OS X, replace LD_LIBRARY_PATH with DYLD_LIBRARY_PATH.

    export PATH=/install/prefix/bin:$PATH
    export C_INCLUDE_PATH=/install/prefix/include:$C_INCLUDE_PATH
    export CPLUS_INCLUDE_PATH=/install/prefix/include:$CPLUS_INCLUDE_PATH
    export LIBRARY_PATH=/install/prefix/lib:$LIBRARY_PATH
    export LD_LIBRARY_PATH=/install/prefix/lib:$LD_LIBRARY_PATH
    

    When you build a program that uses Intel® Cilk™ Plus extensions, add the following option to enable Cilk Plus support and link to the runtime library.

    -fcilkplus
    

    A simple program

    #include <cilk/cilk.h>
    #include <assert.h>
    
    int fib(int n) {
      if (n < 2)
        return n;
      int a = cilk_spawn fib(n-1);
      int b = fib(n-2);
      cilk_sync;
      return a + b;
    }
    
    int main() {
      int result = fib(30);
      assert(result == 832040);
      return 0;
    } 
    

    Confirm that the compiler is working correctly by saving the above code code to a file.

    $ clang -fcilkplus test.c -o test
    $ ./test
    

    You can check that the code is executing in parallel by using the time command and CILK_NWORKERS environment variable to control the number of workers.

    $ CILK_NWORKERS=1 time ./test
    $ CILK_NWORKERS=2 time ./test
    $ CILK_NWORKERS=4 time ./test
    

    Status

    What works right now

    Feature Supported?
    cilk_spawn, cilk_sync check
    cilk_for check
    hyperobjects check
    #pragma simd check
    simd-enabled functions check
    array notation check

    Known issues

    Supported platforms

    OS: Linux, Windows or OS X
    Architecture: x86-64

    License

    LLVM, Clang, and Compiler-rt are distributed under LLVM's "UIUC" BSD-Style license. For details, including information about third-party components, see LICENSE.txt in the code repositories.

    The Intel® Cilk™ Plus runtime library is distributed under a BSD 3-Clause license.

    Contact

    If you would like to report a bug, or make a feature request, you can submit an issue in Github here.