With gmail down, I've been catching up on some reading, namely Ars Technica's unfathomably in-depth review of the new MacOS update, Snow Leopard. It installed on my two Macs like a dream (only problem: had to recreate a printer that disappeared during the update, fixed in 30 seconds), but once done there's not much new to look at. Most of the changes are under the hood.
One such new core technology is Grand Central Dispatch. As Ars explains, it's Apple's new core technology to promote concurrent computing, and to get rid of the dreaded "beach ball" of an unresponsive Mac once and for all. The basic problem it solves is this: threads are a great way of making use of the processing power available in multi-core machines, but they are fiddly to work with and it's hard to know how many to use to optimize performance. GCD solves both these problems elegantly: there's a nice compiler-level syntax for parallel programming, and an eponymous central overseer to make sure that the optimal number of threads is being used at any one time.
It's purely coincidental, but I was struck by some of the design philosophies common to both GCD and our foreach package for parallel programming in R. Both are designed to optimize use of available computing resources: GCD knows how many cores are available and doles out threads accordingly; with foreach you tell it the maximum number of R processes to spawn and it doles them out in much the same way. (On the other hand, foreach's R processes still contend with other processes on the system; GCD has the advantage of being able to manage resources on a global basis. On the other other hand, foreach can span multiple workstations in a cluster, while GCD's domain is one Mac.) Both are designed to reduce the complexity of parallel programming; with GDC you can change one line of code to make a "for" loop's iterations run in parallel, and likewise with foreach. And this summation from Ars on GCD echoes my thoughts on foreach, too:
Those with some multithreaded programming experience may be unimpressed with the GCD. So Apple made a thread pool. Big deal. They've been around forever. But the angels are in the details. Yes, the implementation of queues and threads has an elegant simplicity, and baking it into the lowest levels of the OS really helps to lower the perceived barrier to entry, but it's the API built around blocks that makes Grand Central Dispatch so attractive to developers. Just as Time Machine was "the first backup system people will actually use," Grand Central Dispatch is poised to finally spread the heretofore dark art of asynchronous application design to all Mac OS X developers.
Also new to Snow Leopard is OpenCL, a new programming API opening up the computational muscle of the GPU to developers. It would be nice to exploit this for REvolution R somehow; and perhaps, if OpenCL becomes a cross-platform standard (as it seems it might), it will be possible sometime soon.
Ars Technica: Mac OS X 10.6 Snow Leopard: the Ars Technica review