views:

88

answers:

5

I am working on a programming language. Currently it compiles to C. I would like to be able to include parallel programming facilities natively in my language so as to take advantage of multiple cores. Is there a way to write parallel C programs which is cross-platform? I would prefer to stick to straight C so as to maximize the number of platforms on which the language will compile.

+2  A: 

Use a cross-platform threads library, like pthreads.

C has no standard, built-in support for threads or parallel processing.

bta
This was my initial inclination, but Pthreads seems to be incompletely supported on Windows. I didn't actually try it on Windows (I don't have a Windows box to try it on!) so this may warrant further investigation.
kerkeslager
There's a version of pthreads for windows, http://sourceware.org/pthreads-win32/
Hasturkun
Pthreads is also a very poor approach to writing parallel programs. It offers innumerable opportunities for error and performance pitfalls. It fails at code composability unless the pieces being composed were constructed very carefully.
Novelocrat
A: 

"Straight C" has no concept of threading, so I'm afraid you're out of luck. You'll need to find some sort of cross-platform supporting thread library or port one to the various platforms you want to use. pthreads are as good a place to start as any, I guess.

Carl Norum
+5  A: 

Depending on what you want to do, OpenMP might work for you. It is supported by GCC, VC++, ICC and more.

Georg Fritzsche
A: 

GLib library (from the GTK project) has many useful cross-platform facilities, including threading.

zvrba
A: 

If you're looking to eventually target large-scale parallelism, have a look at Charm++ and its underlying portable machine layer Converse. We run efficiently on machines ranging from multicore desktops to clusters, to BlueGene and Cray supercomputers.

Novelocrat
Charm++ looks interesting, but it is a C++ tool. This question was limited to regular C.
bta