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
- Update to clang/llvm trunk (as of Feb 3 2016)
- CMake based build supported for both compiler and CilkPlus runtime (see _build.sh)
- Update to clang/llvm trunk (as of Dec 2015)
- Windows support
- Miscalleneous bug fixes
December 29, 2015 - Big new update, including:
September 17, 2014 - Binary images of the compiler added for both Linux and Mac.
September 05, 2014 - CilkPlus runtime is building directly from CilkPlus runtime site.
June 26, 2014 - re-base to Clang 3.4 done;
Extended Array Notation is fully supported now;
Some bugs fixed.
October 9, 2013 - #pragma simd and SIMD-enabled functions are now supported.
June 7, 2013 - All known exception handling issues have been resolved.
May 7, 2013 - cilk_for is now supported, including #pragma grainsize. The runtime was updated to the latest version.
Try Cilk Plus/LLVM
Note: Cilk Plus/LLVM does not yet support all of the Intel® Cilk™ Plus extensions. See Status.
Requirements
Most software and hardware requirements are the same as for LLVM. However, support is currently limited to 64 bit Linux and Mac OS X - see status for details on supported configurations and known issues.
CMake version 2.8.8 or greater is required to compile compiler-rt when using the recommended build process. Alternatively, it is also possible to use configure/make by following the directions at http://clang.llvm.org/get_started.html.
Getting the source code
$ 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: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 | |
cilk_for | |
hyperobjects | |
#pragma simd | |
simd-enabled functions | |
array notation |
Known issues
- SIMD-enabled functions and #pragma simd loops are currently not well-vectorized by LLVM.
- Cilk_spawn and Windows EH can't be mixed inside one function
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.