Fine-grained parallelism granularity allows us to run heterogeneous computational tasks effectively. Besides this, the fine-grained approach makes the splitting of your program into tasks easier, especially if these tasks are related to each other and, for example, latter tasks use some computation results of former tasks. However, we will have to trade off some performance, since the CPU has to be used to manage all these tasks as well.
To find out how fine-grained granularity can affect performance for a real task, let's implement a ray tracing algorithm using TPL and compare it to the results that we got in the beginning using an optimal number of threads. To implement the fine-grained program version, we will just create a task for each image column and start it immediately. The implementation code is as follows:
var tasks = new List<Task>(); var fineSw = Stopwatch.StartNew(); for (var i = 0; i < _width; i++) { var col = i...