Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take advantage of multi-cpu in c++?

I work in lab and wrote multithreaded computational program, on C++11 using std::thread. Now I have an opportunity to run my program on multi-cpu server.

Server:

  • Runs Ubuntu server
  • Has 40 Intel CPU's

I know nothing about multi-cpu programming. First idea, that comes into my mind to run 40 applications and then glue their results together. It is possible, but I want to know more about my opportunities.

  1. If I compile my code on server by it's gcc compiler, does resulting application take advantage of multi-cpu?
  2. If #1 answer depends, how can I check it?

Thank you!

like image 628
DoctorMoisha Avatar asked Sep 04 '15 17:09

DoctorMoisha


People also ask

How does multiple CPU affect performance?

A CPU that offers multiple cores may perform significantly better than a single-core CPU of the same speed. Multiple cores allow PCs to run multiple processes at the same time with greater ease, increasing your performance when multitasking or under the demands of powerful apps and programs.

What applications take advantage of multi-core?

The following are examples of CPU-hungry applications that can take advantage of multiple cores: Photo and video editing apps— Adobe Photoshop, Adobe Premier, iMovie. 3D modeling and rendering programs — AutoCAD, Solidworks. Graphics-intensive games — Overwatch, Star Wars Battlefront.

Is multi-core good for programming?

Using multicore programming helps to split your system into multiple parallel tasks, which run simultaneously, speeding up the overall execution time.

Why do we need multiple processors?

Different computing tasks take different resources. The number one factor of whether programs will run smoothly is how many cores you have. If you want to run multiple apps at once or more resource-intensive programs, your device needs multiple CPU cores.


1 Answers

If your program runs multithreaded your OS should take care automatically that it uses the CPUs available.

Make sure to distribute the work you have to do to about the same number of threads there are CPUs you can use. Make sure it is not just one thread that does the work and the other threads are just waiting for the termination of this thread.

like image 138
Matthias Wimmer Avatar answered Oct 08 '22 09:10

Matthias Wimmer