Executing C++ program on multiple processor machin

2020-07-20 05:00发布

I developed a program in C++ for research purpose. It takes several days to complete.

Now i executing it on our lab 8core server machine to get results quickly, but i see machine assigns only one processor to my program and it remains at 13% processor usage(even i set process priority at high level and affinity for 8 cores).

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

How i can get true benefit from the powerful server machine? Thanks in advance.

4条回答
Fickle 薄情
2楼-- · 2020-07-20 05:15

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.

查看更多
SAY GOODBYE
3楼-- · 2020-07-20 05:29

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

查看更多
手持菜刀,她持情操
4楼-- · 2020-07-20 05:30

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.

查看更多
Viruses.
5楼-- · 2020-07-20 05:30

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.

查看更多
登录 后发表回答