Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use quad core CPU in application

For using all the cores of a quad core processor what do I need to change in my code is it about adding support of multi threading or is it which is taken care by OS itself. I am having FreeBSD and language I am using is C++. I want to give complete CPU cycles to my application at least 90%.

like image 529
Mayank Avatar asked Mar 30 '10 13:03

Mayank


People also ask

How do I dedicate CPU cores to a program?

To set CPU Priority, right-click on any process in Task Manager and select Go to details. Next, right-click on the highlighted process and click on Set Priority. Now, choose priority from the list that pops up. If you want your process to run as soon as it needs, select Realtime.

How do I force a program to use multiple cores?

Type 'msconfig' into the Windows Search Box and hit Enter. Select the Boot tab and then Advanced options. Check the box next to Number of processors and select the number of cores you want to use (probably 1, if you are having compatibility issues) from the menu. Select OK and then Apply.


2 Answers

You need some form of parallelism. Multi-threading or multi-processing would be fine.

Usually, multiple threads are easier to handle (since they can access shared data) than multiple processes. However, usually, multiple threads are harder to handle (since they access shared data) than multiple processes. And, yes, I wrote this deliberately.

If you have a SIMD scenario, Ninefingers' suggestion to look at OpenMP is also very good. (If you don't know what SIMD means, see Ninefingers' helpful comment below.)

like image 189
sbi Avatar answered Nov 06 '22 07:11

sbi


For multi-threaded applications in C++ may I suggest Boost.Thread which should help you access the full potential of your quad-core machine.

As for changing your code, you might want to consider making things as immutable as possible. State transitions between threads are much more difficult to debug. There a plethora of things that could potentially happen in unexpected ways. See this SO thread.

like image 40
wheaties Avatar answered Nov 06 '22 05:11

wheaties