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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With