I am experimenting with parallel programming. I have a normal loop:
for (int i = 0; i < 100000; i++)
{
Console.WriteLine("Thread ID: {0} and i is " + i + " Time Elapsed: " + sw.Elapsed,
Thread.CurrentThread.ManagedThreadId);
}
This loops just increments numbers to 100000
Can I use this for loop and turn it into a Parallel.For loop to count numbers to 100000 but using all CPUs in parallel?
Also, when using a Parallel.For, what are the parameters needed? How would you use it in a very basic way?
If you want to use Parallel.For, you need to some synchronization, may be using locks as well.
If you really want to use Parallel.For, I would suggest you to please follow the link, it beautifully explains Parallel.For…
http://msdn.microsoft.com/en-us/magazine/cc163340.aspx
Hope, it helps