using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using System.Diagnostics; class c1906 { static void Main() { const int n = 100000000; int[] x = new int[n]; int total = 0; int i; double t1,t2,t3,t4,t5,t6,t7; Console.WriteLine(DateTime.Now); Console.Write("Program starts"); var sw = Stopwatch.StartNew(); t1=sw.ElapsedMilliseconds / 1000.0; Console.WriteLine(" {0,5:0.000}",t1); parallel_initialise(x,1); Console.Write("Parallel initialisation"); t2=sw.ElapsedMilliseconds / 1000.0; t3=t2-t1; Console.WriteLine(" {0,5:0.000}",t3); t1=t2; t3=t2; for (i=0;i ( 0, z.Length, () => 0, (j, loop, subtotal) => { subtotal += z[j]; return subtotal; }, (xx) => Interlocked.Add(ref total, xx) ); return(total); } static void parallel_initialise(int [] z , int n) { Parallel.For ( 0, z.Length, j => { z[j] = n; } ); } }