Let Snow Leopard Roar

by Eli on October 29, 2009

For those who use Snow Leopard you have probably noticed how much snappier the OS is than its predecessor. Much of the optimizations in Snow Leopard is thanks to several new and emerging tools called LLVM, Clang, and OpenCL. What’s more is that we can use these tools to speed up some of our basic command line executable files and our own code (if it’s written in C, C++, and Python). This means we can see speed improvements for our coding projects.

LLVM is the next stage in the evolutionary chain of C and C++ compilers. It can compile about any bit of code that is currently compiled by GCC now. For gutsy details I suggest reading the overview section on the LLVM website. One caveat: LLVM has the ability to do array optimization, but it is turned off by default by the LLVM and Apple group. If you plan to compile code that depends on auto arrays I’d suggest using GNU compilers at the moment.

Clang is front-end to LLVM. It can only compile C code and is much faster than GCC and LLVM. On top of that it optimizes the compiled code even more than LLVM. It has better diagnostics to why a compiling job has failed. Almost as good as Python’s Traceback! If you can use Clang you’re golden.

Then there’s OpenCL. Ever heard of CUDA? It’s like CUDA gone agnostic and can work with both NVIDIA and ATI graphics cards for scientific parallel processing.  Like CUDA, OpenCL can work with a cluster of GPU. It can also harness multiple CPU as well. Imagine writing a program that can harness your graphics card for small jobs. If a super computer were ever needed and it supported OpenCL, your code would only require almost no change and it could harness all the CPU cores.

If you read this far, then I think you may be convinced that using these tools is necessary for your work. Documentation on how to setup your Mac to use these tools is still sparse on the web, so here’s some instructions on how to link your environment.

Linking to Apple Developer Bin and Lib

In  your .bash_profile put in the following to use LLVM, Clang, and OpenCL.

export PATH=/Developer/usr/bin/:$PATH
export PATH=/Developer/usr/lib/:$PATH
export PATH=/Developer/usr/libexec/:$PATH

Using LLVM or Clang

Add the following text to your .bash_profile to use LLVM and Clang for compiling code when you use Make.

export CC=’clang -w’
export CXX=’llvm-g++


OpenCL is a completely different beast from LLVM and Clang. At this point it’s learning how to program C code using OpenCL. Since this would take quite a few more lines to document, follow this link at MacResearch to learn more about it and how to use it. For Python users there is a module called PyOpenCL, written by Andreas Klockner, that harnesses OpenCL’s power.


{ 2 comments… read them below or add one }

1 Michael Galloy October 29, 2009 at 11:12 pm

GPULib offers CUDA support for IDL. It doesn’t have OpenCL support yet, but OpenCL is basically CUDA with a different prefix to the routine names.

Full disclosure: I work for Tech-X and do work on the GPULib bindings for IDL.


2 Jonathan Foster November 4, 2009 at 11:45 am

Hey Eli,

I just found this blog. Good stuff all around. You link to John Siracusa’s Snow Leopard review at Ars Technica in your post, but I’d like to just highlight that article for anyone interested in these topics. Starting on about page 8 and going through page 15 is really an excellent introduction to all the new technologies you discuss here.


Leave a Comment

Previous post:

Next post: