Enter Cilk Plus

It was an interesting day yesterday. 10 hours on the road from Kista all the way up north to Luleå for the annual moose hunt. With my Honda Jazz, not really built for highways, the radio Bandit FM blaring in the speakers and with the mornings Cilk Plus Keynote lectures from SICS multicore days still being processed I was more than a little tired when I finally arrived.

The Cilk plus seems very promising. Intel bought up the Cilk Arts company and is working now towards fully commercializing it , for now free as a “technology preview” — and maybe more in focusing on getting the revenues from the Cilk behind the curtains technology such as CilkScreen that guarantees to find the parallel code determinacy races.

In short Cilk Plus provides an easy way for the programmer to expose the parallelism. This used to be most used, and most efficient for library writers, low lewel, embedded type of optimization. But now since Intel is stepping it up a notch and is really promoting Cilk Plus and especially its many advantages to OpenMP I believe Cilk Plus has a real chance in making it into the application software as well.

A word about Cilk Plus vs OpenMP. OpenMP is an open standard so to compete with that Intel has made Cilk Plus open as well and welcome other compiler vendors to implement it. In fact it’s well in progress for GCC and a patch to support the most important Cilk features was released as a GCC 4.7 patch this August. Cilk Plus also scaled much better than OpenMP and does not penalize other processes as OpenMP does.

Two affiliates with Intel was at SICS Multicore Days to promote Cilk plus. Dr. Arch Robinson from Intel who showed practical easy-to-use programming examples (here’s his cilk plus blog series and Intel blogs for Cilk Plus). And the Cilk Plus keynote from Professor Charles E Leiserson from MIT (a Cilk founder). I don’t think the multicore days presentations are available yet but I found this presentation that was borrowed from Charles’ lecture and it seems to be almost the same: http://developer.amd.com/afds/assets/presentations/2080_final.pdf

Let’s cut to the chase let’s see a classic simple example of Cilk Plus. The example is the fibonacci calculation as shown in this Intel presentation.

int fib(int n)
{
   if (n < 2) return n;
   int x = fib(n-1);
   int y = fib(n-2);
return x+y;
}

Which with nested parallelism would look like this

int fib(int n)
{
   if (n < 2) return n;
   int x = cilk_spawn fib(n-1);
   int y = fib(n-2);
 cilk_sync;
  return x+y;

Another nice feature is the cilk_for that for array and matrix operations many times can replace the normal for-loop. At scope end the cilk_for will synchronize the parallel calls. This is implied implicitly and can also, as shown above, be forced wherever with cilk_sync

Here’s another view of Cilk Plus from Dr.Dobb, unfortunately it does not describe CilkScreen which I think goes with Cilk Plus as hand-in-glove 🙂

As soon as the moose hunt is done with I’m sure to check out Cilk Plus 🙂

Advertisements

About kjellkod

Software Engineer by trade, (former?) Martial Artist and Champion by strong will and small skill... and a Swede by nationality :)
This entry was posted in C++, Software Engineering. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s