开发者

How does one write cross-platform parallel programs in C?

开发者 https://www.devze.com 2023-01-07 16:29 出处:网络
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

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开发者_JAVA技巧 which the language will compile.


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


Use a cross-platform threads library, like pthreads.

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


"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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消