简体   繁体   English

如何用C编写跨平台并行程序?

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

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. 目前它编译为C.我希望能够以我的语言本地包含并行编程工具,以便利用多个内核。 Is there a way to write parallel C programs which is cross-platform? 有没有办法编写跨平台的并行C程序? I would prefer to stick to straight C so as to maximize the number of platforms on which the language will compile. 我宁愿坚持直接C,以便最大化语言编译的平台数量。

Depending on what you want to do, OpenMP might work for you. 根据您的要求, OpenMP可能适合您。 It is supported by GCC, VC++, ICC and more. 它得到了GCC,VC ++,ICC等的支持。

Use a cross-platform threads library, like pthreads . 使用跨平台线程库,如pthreads

C has no standard, built-in support for threads or parallel processing. C没有标准的内置支持线程或并行处理。

"Straight C" has no concept of threading, so I'm afraid you're out of luck. “Straight C”没有线程概念,所以我担心你运气不好。 You'll need to find some sort of cross-platform supporting thread library or port one to the various platforms you want to use. 您需要找到某种跨平台支持的线程库或端口1到您想要使用的各种平台。 pthreads are as good a place to start as any, I guess. 我想,pthreads和任何一个一样好。

GLib库(来自GTK项目)有许多有用的跨平台设施,包括线程。

If you're looking to eventually target large-scale parallelism, have a look at Charm++ and its underlying portable machine layer Converse . 如果您希望最终以大规模并行为目标,请查看Charm ++及其底层便携式机器层Converse We run efficiently on machines ranging from multicore desktops to clusters, to BlueGene and Cray supercomputers. 我们在从多核台式机到集群,到BlueGene和Cray超级计算机的各种机器上高效运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM