Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to simulate the maximum CPU load?

I have to test an embedded computer for the most extreme conditions of generated heat and current draw, and to do so I want to write a program that employs the CPU resource as much as possible of a quad core CPU (one thread per core). Can you suggest something that would be very CPU hungry?

I have to do this for Linux on a ARMv7 and the language is C or C++, the other examples I have found are either for Windows or not in C/C++.

I am trying something like this on my Windows computer and apparently it is working as it takes 12% of total CPU power (which is a i7 quad core 2 threads per core):

float x = 1.5f;
while (1)
{
    x *= sin(x) / atan(x) * tanh(x) * sqrt(x);
}

I don't know how to make it multi-thread.

like image 514
Mark Miles Avatar asked Jan 02 '15 21:01

Mark Miles


1 Answers

Your code is serial. You have eight available threads (4 cores * 2 threads per core = 8 total threads), and your current code uses one of them for 1 thread / 8 available = 12.5% of your CPU. If you have to write your own code (and not use a pre-existing intensive code as already suggested by others), I would recommend putting a #pragma omp parallel above your while loop and compiling with the -fopenmp flag (assuming you are using MinGW, if not, the exact option may vary) so that you use all of the available threads instead.

like image 93
wolfPack88 Avatar answered Oct 13 '22 06:10

wolfPack88