Concurrency made easy?

With the wide availability of multicore and multiple processor systems, I've decided it's time for me to learn a new language. Until now it's been pretty much straight C, but I really don't want to do explicit threads if possible. I have a few projects that should be highly parallelizable, eg counting the number of random graphs with a particular property. But what language to use?

Functional languages seem like a natural, but how are the actual implementations? Which implementations of which languages will handle the concurrency without having to explicitly count processors and create threads. It should be fairly readable, and available for Linux and Mac OS X. Any suggestions?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Lightweight Threads vs. Threadless

I don't know of many languages that support concurrency without threads. The only things that come to mind are data-parallel languages, and parallel runtimes for pure functional languages. Lightweight thread systems are probably enough of a departure from threading in C to be interesting.

For the data-parallel programming there are many lanuages like High Performance Fortran which provide operations over arrays. NESL extended the data parallel approach to structured data, and that research continues as Data Parallel Haskell (the programming model is implemented, a serious SMP execution engine is being developed).

The only parallelizing runtime for a function language that I know of is Glasgow Parallel Haskell, which is getting a bit dated. The language uses annotations to suggest what parts of pure code might usefully be executed in parallel. It's a bit tough to get running.

I'm not sure you really need to avoid threads to have a nice programming model. Many systems make threads light on memory and cheap to create and schedule, like Oz, Stackless Python, Erlang, etc. With these systems, you can pretty much make as many threads as you have concurrent tasks, and leave distributing the work between processors up to the runtime (be careful, not all these implementations can actually use multiple processors). Also, all these systems offer some communication tools that make it easier to get threads talking that the locks and shared memory of threads in C, whether it's message passing, futures, data flow (both in Oz), or transactional shared memory (STM in Haskell).

without threads

I don't know of many languages that support concurrency without threads.

ToonTalk, Actor model, Janus, Pictorial Janus.

(I have not seen these demonstrated on Linux).

Erlang is the most obvious

Erlang is the most obvious answer. It uses the message-passing model rather than shared state, and supports automatic scheduling of processes to different CPUs.

And was discussed here many

And was discussed here many times, so you might want to check the archives!

Coordination techniques in imperative languages

Within the C++ and .NET world, I thought I'd mention a couple of projects that seem interesting:


Concurrency and Coordination Runtime
(video, paper): This is a library that makes message-pasing based programming using ports easier to use in C#.

Also, Herb Sutter has recently talked about his Concur project which introduces some concurrency-related programming abstractions into C++. These include the notion of active classes in which method calls are asychronous; coordination is achieved by means of "future" objects, which are essentially return values represented by proxy objects which block for an operation to complete when you redeem them. He said he would make his presentation available online, but I can't find it yet.

-K

Concurrent C

Concurrent C implements parallel subroutine evaluation. You can look it up on the wiki. It's pretty close to C. Unfortunatly, not all subroutines like being called in parallel.

Alice

Alice "is a functional programming language based on Standard ML, extended with rich support for concurrent, distributed, and constraint programming". Runs on x86, but currently has problems on OS X because of GTK issues.

Connective Logic - alternative approach to concurrency

We have been developing a machine translatable graphical coordination language which we call the Concurrent Description Language (CDL).

The solution is defined in what we call a ‘circuit’ and each of these can be thought of as an autonomously executing entity – and so a program is a colony of entities whose behaviour is synchronized by their exchange of events. Circuitry is constructed from a finite set of arbitrarily composable ‘event operators’ and each individual circuit is likely to contain further autonomously executing components. Because of this, CDL applications can end up with very high logical concurrencies and we therefore have a lightweight alternative to replace conventional threads.

Since a lot of the logic is derived from the manner in which these components are composed, rather than the properties of the components themselves, we refer to the programming paradigm as ‘connective logic’. The component set also contains ‘active’ objects which perform processing operations, and these are programmed in conventional text languages (C++ etc).

For more info see:

Brief Summary

Detailed Tech Doc

If C is what you're familiar

If C is what you're familiar with, you probably want to use Cilk, which is a high-performance language that doesn't use explicit threads.

It works best for "highly parallelizable" applications like you describe; it tends to become cumbersome if your application is not well-structured.