I have some code which I am currently optimizing for concurrency in multicore architectures. In one of my classes, I found a nested foreach
loop. Basically the outer loop iterates through an array of NetworkInterface
objects. The inner loop iterates though the network interfaces IP addresses.
It got me thinking, is having Nested Parallel.ForEach
loops necessarily a good idea? After reading this article (Nested Parallel.ForEach Loops on the same list?) I am still unsure what applies where in terms of efficiency and parallel design. This example is taking about Parallel.Foreach
statements being applied to a list where both loops are performing operations on that list.
In my example, the loops are doing different things, so, should I:
- Use nested Parallel.ForEach loops?
- User Parallel.ForEach on the parent loop and leave the inner loop as-is?