3

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.

DataMiner
  • 325
  • 1
  • 3
  • 16
  • The 13% CPU usage may be a result of heavy I/O use, i.e. disk reads/writes. – arne Oct 20 '11 at 09:09
  • 2
    1/8 of the CPU (one of its cores) being 100% utilized equals to 12.5% overall usage. There's the 13%. – Flo Oct 20 '11 at 09:15

4 Answers4

5

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.

Rob
  • 306
  • 1
  • 5
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • And, of course, first use a profiler to find out what parts are so slow. There's usually little point in parallelizing your splash screen code ;) – MSalters Oct 20 '11 at 11:27
  • One should always tune slow code first. That's assumed. OP asked how he could use his multiple processors ("powerful machine"). – Ira Baxter Oct 20 '11 at 17:05
3

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

Paul R
  • 208,748
  • 37
  • 389
  • 560
cnicutar
  • 178,505
  • 25
  • 365
  • 392
  • 2
    Agree. Here is a real-world example explaining your mistake. Imagine a pregnant woman : she needs 9 monthes to "make" a baby. Now if you add 7 more women, the baby won't arrive faster because pregnancy is not meant to be shared amongst several women... Same for your program, 8 core is not faster than 1 core in your case. You must have a way to split the work into parts, assign them to workers and then reassemble the results. – Offirmo Oct 20 '11 at 13:25
  • 2
    @Offirmo Nice example but I don't see it as "real-world" :)) – cnicutar Oct 20 '11 at 13:28
  • Do you know any example of boost::threads runnig on separate processors? For me ([see](http://stackoverflow.com/questions/19063079/how-to-run-boostthreads-on-many-processors)) all they run on one processor with others not used. – cpp Sep 28 '13 at 15:52
1

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.

Nicola Musatti
  • 17,834
  • 2
  • 46
  • 55
0

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.

Community
  • 1
  • 1