I read that .NET C# has task and data parallelism built in. If I run a for/foreach loop in my program in a computer that has 4 cores (4 windows the Windows Task Manager), will the loop be evenly distributed into the 4 cores? If not, why isn’t the for/foreach loop doesn’t run in 4 cores parallel in default?
Generally speaking, is parallelism better than conventional programming? Does the benefits outweigh the drawbacks? I’m doing a lot of data processing (bunch of pulls, for/foreach loops) and need to complete these for/foreach loops faster.
it’s not running on 4 cores because it is not efficent or needed every time.
it’s depending on your program and the load of your program. it’s not efficent to parallelize a function that did not take 1ms/cycle. if you do a lot of long running calcuations or searches over a big field of data that can be splitted up sensible you could / should parallelize your loops.
for that topic i recommend reading http://www.amazon.com/Multi-Core-Programming-Increasing-Performance-Multi-threading/dp/0976483246/ref=sr_1_fkmr0_2?ie=UTF8&qid=1336440123&sr=8-2-fkmr0