Executing C++ program on multiple processor machine

匆匆过客 提交于 2019-12-04 12:48:30
Ira Baxter

Partition your code into chunks you can execute in parallel.

You need to go read about data parallelism and task parallelism.

Then you can use OpenMP or MPI to break up your program.

cnicutar

(It is a simple object oriented program without any parallelism or multi threading)

How i can get true benefit from the powerful server machine?

By using more threads. No matter how powerful the computer is, it cannot spread a thread across more than one processor. Find independent portions of your program and run them in parallel.

  • C++0x threads
  • Boost threads
  • OpenMP

I personally consider OpenMP a toy. You should probably go with one of the other two.

You have to exploit multiparallelism explicitly by splitting your code into multiple tasks that can be executed independently and then either use thread primitives directly or a higher level parallelization framework, such as OpenMP.

HostileFork

If you don't want to make your program itself use multithreaded libraries or techniques, you might be able to try breaking your work up into several independent chunks. Then run multiple copies of your program...each being assigned to a different chunk, specified by getting different command-line parameters.

As for just generally improving a program's performance...there are profiling tools that can help you speed up or find the bottlenecks in memory usage, I/O, CPU:

https://stackoverflow.com/questions/tagged/c%2b%2b%20profiling

Won't help split your work across cores, but if you can get an 8x speedup in an algorithm that might be able to help more than multithreading would on 8 cores. Just something else to consider.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!