There are various reasons I might want to spike the CPU temperature as much as possible:
- Testing cooling setups.
- Increasing the fan speed without messing with the BIOS settings.
- Testing the effect of temperature throttling on other processes running on the same die.
I know that modern CPUs have numerous functional units and various tricks to try to keep as many of them occupied as possible. So, I know this answer might have some variants for specific CPU micro-architectures.
But, what code can I run that will do the most to spike the CPU temperature?
Inline assembly is fine. But, it would be nice to have an answer in C or C++.
I did write this function that I hope will keep several different functional units fairly occupied with pointless calculation:
void busy_busy_busy()
{
using uint_t = ::std::uint64_t;
const auto maxuint = ::std::numeric_limits<uint_t>::max();
::std::random_device random_device;
::std::mt19937_64 generator(random_device());
::std::uniform_int_distribution<uint_t> ints(0, maxuint >> 1);
::std::uniform_real_distribution<long double> doubles(0, 1);
long double starting = doubles(generator);
long double const one_third = 1.0l / 3.0l;
while (starting != one_third) {
auto tmp = starting;
tmp *= doubles(generator);
starting *= ints(generator);
starting += tmp;
starting /= maxuint >> 2;
}
}
Off-the-shelf benchmarks are typically not designed to do this. They're designed to test speed of execution of either loads that are purposefully synthetic, or loads that are designed to mimic real-world usage. They will increase the CPU temperature, but I'm after code that's very specifically designed to increase the CPU temperature with a synthetic load that would likely never occur in these benchmarks.
I, personally, have an AMD Ryzen 9 3950X.