GNU has announced that GCC 5.0 will provide full support for Cilk Plus. Cilk Plus is an extension to the C and C++ languages to support data and task parallelism on multi-core, vector and Intel Xeon Phi coprocessors.It is reputed to be quite efficient and looks to be easy to use. The Intel **icc** compiler has supported Cilk Plus for years. GNU support now makes Cilk Plus available to all. A subset of Cilk Plus (minus cilk_for and ZCA annotations) has been merged into the mainline GCC 4.9 distribution. Be sure to pick the right license. The Github Cilk Plus/LLVM project implements the Intel® Cilk™ Plus language extensions in the Clang frontend for LLVM.

Following are a sequential and Cilk Plus matrix multiplication example from “Graduate from MIT to GCC Mainline with Intel® Cilk™ Plus”

1 2 3 4 5 6 7 8 |
template<typename T> void matmul(int ii, int jj, int kk, T *a, T *b, T *product) { for (int i = 0; i < ii; ++i) for (int j = 0; j < jj; ++j) for (int k = 0; k < kk; ++k) product[i * jj + j] += a[i * kk + k] * b[k * jj + j]; } |

Here is the Cilk Plus parallel example

1 2 3 4 5 6 7 8 |
template<typename T> void matmul_vec(int ii, int jj, int kk, T a[], T b[], T product[]) { for (int i = 0; i < ii; ++i) for (int j = 0; j < jj; ++j) product[i * jj + j] = __sec_reduce_add(a[i*kk:kk:1] * b[j:kk:jj]); } |

The statement
a[i*kk:kk:1] * b[j:kk:jj] multiplies each element of a row of matrix a against a column of matrix **b**, producing a temporary vector of length **kk**. The call to *__sec_reduce_add()* sums the elements of the temporary vector.

For more information, view the 17-video series by Intel to introduce and teach Cilk Plus.

## Leave a Reply