O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Transforming Sequential Code to Parallel Code

Until recently, most Visual Basic code was written with a sequential and synchronous execution approach. Therefore, a lot of algorithms have been designed with neither concurrency nor parallelism in mind. Typically, you won't find algorithms that can be completely converted to fully parallelized and perfectly scalable code. It could happen, but it represents an ideal situation and it isn't the most common scenario.

When you have sequential code and you want to take advantage of potential parallelism to achieve better performance, you have to find hotspots. Then you can convert them to parallel code, measure speedups, identify potential scalability, and ensure that you haven't introduced new bugs while transforming the existing sequential code to parallel code.

Note
A hotspot is a part of the code that takes significant time to run. You can achieve speedups if it is split into two or more pieces running in parallel. If part of the code doesn't take significant time to run, the overhead introduced by TPL could reduce the performance improvement to worthless or even make the parallelized code run slower than the sequential version. Once you begin working with the different options offered by TPL, it is going to be easier for you to detect the hotspots in sequential code.

Detecting Hotspots

The code discussed in this section is from code file Listing01.sln and shows an example of a very simple console application that runs two sequential ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required