Gastón Hillar

Dr. Dobb's Bloggers

Parallelized Algorithms Are Very Useful for Battery Powered Devices

January 18, 2011

Parallelized algorithms aren't just for desktop computers or servers. If you parallelize your code to take advantage of mobile multicore CPUs, you can create more responsive software without consuming excessive battery life.

Parallelized algorithms aren't just for desktop computers or servers. If you parallelize your code to take advantage of mobile multicore CPUs, you can create more responsive software without consuming excessive battery life.

Multicore CPUs are becoming part of any modern device with a CPU. However, some developers have doubts about the advantages of running parallelized algorithms on battery powered devices. Modern mobile multicore CPUs have many power states. If your algorithm uses all the CPU power, the CPU will run on the highest power state. However, if your parallelized algorithm uses all the CPU power in an efficient way, the algorithm will require less time to finish. If you consume more power but you require less time, you can even save battery life when you take advantage of multicore. In addition, the existence of turbo modes, such as Intel Turbo Boost, makes some single-threaded applications consume almost the same power as multithreaded applications. This situation happens because Intel Turbo Boost overclocks certain cores on demand, as explained in "Measuring Speedup is Challenging with Intel Turbo Boost Technology."

When Intel Turbo Boost overclocks certain cores, the CPU increases its power consumption. Thus, this overclocked CPU might consume almost the same power as the CPU running code in many non-overclocked cores.

I ran many tests with the Silverlight 4 application explained in "Silverlight 4 Makes it Easy to Count Logical Cores." I ran these tests on an Intel Core i7 820QM CPU and I've used Microsoft Windows 7 Ultimate 64-bit edition. This CPU has four physical cores and eight hardware threads. The Silverlight 4 application doesn't represent the most efficient parallelized algorithm because it uses static partitioning. However, the application provides an interesting workload and allowed me to compare a sequential version with its parallelized version. The test starts with a fully charged battery and then measures the total remaining battery charge when the Silverlight 4 application runs the algorithm five times. In addition, the test considers the total time required to run the algorithm five times.

The parallelized version with Intel Turbo Boost enabled took 220 seconds to complete and left the battery with a total charge of 95%. Remember that the parallelized version can use even more efficient code. The sequential version with Intel Turbo Boost enabled required more time to complete and left the battery with a total charge of 92%. The sequential version with Intel Turbo Boost disabled provided the worst results. Which version would you choose to achieve the best performance while maximizing battery life? I would choose the parallelized version, and I would leave Turbo Boost enabled. You can run these test by yourself and draw your own conclusions. This simple example allows you to understand the importance of parallelized algorithms for battery-powered devices. The results are even better when you take full advantage of the underlying hardware architecture and its advanced capabilities.

You can also maximize battery life when you have code that doesn't require a long time to run. If you run code in different tasks or threads, you can make the CPU run in low power states to process the same workload that would require a higher power state for the sequential version. Remember that asynchronous programming is very important to provide the user with a responsive UI while taking advantage of multiple cores.

When you want to compare battery consumption of a serial algorithm versus its parallelized version, it is very important to consider the time required by each version. If the parallelized version requires less time, you will save battery life. Thus, the user will be very happy with both performance and battery consumption.

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!