转自Stackoverflow:Parallelization: pthreads or OpenMP?
来源:互联网 发布:碎屏 mac 壁纸高清 编辑:程序博客网 时间:2024/06/11 01:03
Q:
Most people in scientific computing use OpenMP as a quasi-standard when it comes to shared memory parallelization. Is there any reason (other than readability) to use OpenMP over pthreads? The latter seems more basic and I suspect it could be faster and easier to optimize. A1: It basically boils down to what level of control you want over your parallelization. OpenMP is great if all you want to do is add a few #pragma statements and have a parallel version of your code quite quickly. If you want to do really interesting things with MIMD coding or complex queueing, you can still do all this with OpenMP, but it is probably a lot more straightforward to use threading in that case. OpenMP also has similar advantages in portability in that a lot of compilers for different platforms support it now, as with pthreads. So you're absolutely correct - if you need fine-tuned control over your parallelization, use pthreads. If you want to parallelize with as little work as possible, use OpenMP. Whichever way you decide to go, good luck! A2: One other reason: the OpenMP is task-based, Pthreads is thread based. It means that OpenMP will allocate the same number of threads as number of cores. So you will get scalable solution. It is not so easy task to do it using raw threads. The second opinion: OpenMP provides reduction features: when you need to compute partial results in threads and combine them. You can implement it just using single line of code. But using raw threads you should do more job. Just think about your requirements and try to understand: is OpenMP enough for you? You will save lots of time. A3: OpenMP requires a compiler that supports it, and works with pragmas. The advantage to this is that when compiling without OpenMP-support (e.g. PCC or Clang/LLVM as of now), the code will still compile. Also, have a look at what Charles Leiserson wrote about DIY multithreading (1). Pthreads is a POSIX standard (IEEE POSIX 1003.1c (2)) for libraries, while OpenMP specifications (3) are to be implemented on compilers; that being said, there are a variety of pthread implementations (e.g. OpenBSD rthreads, NPTL), and a number of compilers that support OpenMP (e.g. GCC with the -fopenmp flag, MSVC++ 2008). Pthreads are only effective for parallelization when multiple processors are available, and only when the code is optimized for the number of processors available. Code for OpenMP is more-easily scalable as a result. You can mix code that compiles with OpenMP with code using pthreads, too. 1: cilk.com/multicore-blog/bid/5847/The-Folly-Of-Do-It-Yourself-Multithreading 2: opengroup.org/onlinepubs/009695399/basedefs/pthread.h.html 3: openmp.org/wp/openmp-specifications/ A4: you get the complete answer here: http://openmp.blogspot.com/2011/01/what-is-open-mp-why-open-mp.html it clearly explains why openmp? A brief of it as far as i could understand is,
- 转自Stackoverflow:Parallelization: pthreads or OpenMP?
- MPI/Pthreads/openmp
- 转自StackOverflow:MPI, Sungrid vs JPPF?
- 手机UI设计建议(转自stackoverflow的回复)
- 【转自stackoverflow】关于android 4.4 获取系统图片问题
- 高性能计算的线程模型:Pthreads 还是 OpenMP
- Pthreads
- pthreads
- pthreads
- javascript duck typing范例(转自http://stackoverflow.com/questions/3379529/duck-typing-in-javascript)
- Deploying my application at the root in Tomcat(转自StackOverFlow,做记录)
- StackOverFlow
- StackOverflow
- [stackoverflow转帖翻译练习] Windows Phone 7 App Slows down in Wi-Fi than 3G or LAN
- 【转自csdn blog】checked or unchecked
- VC++中的OpenMP编程:设置与简要说明(转自:Colin.Cpper)
- 在 xp 中安装 jdk8 (译自stackoverflow)
- [转]OpenMP 入门
- 数据库连接参数
- Mac OS X FAQ整理(都是网络资源)
- Solving the absence of Android source...
- RSSI
- linux命令:du
- 转自Stackoverflow:Parallelization: pthreads or OpenMP?
- synchronizing using completion function
- 对于网站开发中,经常需要取得URL中的参数值。
- abap 在table control(表控件) 实现查找功能
- iPhone 隐藏Status Bar和修改程序名称的小技巧
- linux 应用程序调试初步
- OpenGL怎么用
- 如何判断Javascript对象是否存在
- tomcat + ssl