Tuesday, August 23, 2011

Cilk

Cilk. Not Silk.


This is another parallel programming paradigm from MIT where the design goal was to allow the programmer to concentrate on expressing parallel constructs while the Cilk runtime takes care of the scheduling etc. Cilk has a commercial edition and was acquired by Intel in 2009 but recently, Intel open sourced Cilk Plus and available in the "cilkplus" branch in GCC 4.7 so i'm expecting a lot of activity in the next 12 months.

Issues getting Cilk to build on your operating system

Ubuntu 11
This OS comes with the GNU compiler suite version at 4.5 but there are issues while building the Cilk compiler, otherwise known as cilkc. The issue is that the Cilk-C compiler doesn't like unnamed bit fields though this is perfectly legal with typical C compilers on Mac OS X and Ubuntu 11/10.

Solving this unnamed bit fields is actually easy. Just give it a name and make sure there's no name collision. There is 1 file you need to take care and you can just give a unique name to the unnamed bit field and re-build your project.
  • /usr/include/bits/waitstatus.h

Mac OS X

This OS comes with a pre-installed GNU compiler suite customized for Apple at 4.2.1 Again it faces the similar problems as encountered in Ubuntu 11. This time round, the files are different and that's owed to the fact that although they are both Linux-es, their kernel files are arranged in another manner.

Fix the following files by providing a dummy name that's unique
  • /usr/include/stdlib.h
  • /usr/include/mac/i386/_structs.h
Another issue concerns the concept of "restrict" pointers and how Cilk-c compiler ignores it on the GCC 4.2.1 on Mac OS X. You can go read up about it on Wikipedia or your favourite C authors/books but the observation here is that Cilk doesn't understand restricted pointers in the C API memcpy(...) when its attempting to compile its example cilk programs. Looks to me like a self-test where a compiler  This obviously can be a TODO for an enthusiast but the simplest thing i did was to ignore the build of those example programs but turns out skipping them is a bad idea as the final binary "cilkc" cannot be generated.

Drats.

The simplest solution is to replace the "offending" functions with their equivalents in "standard" C. e.g. coding a for-loop to replace memcpy(...) & strcpy(...)

Having that done, cilkc was generated and its static/dynamic libraries are generated.

Hopefully this helps and the next couple of posts, i'll write something up about using Cilk

0 comments: