using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using System.Diagnostics; class c1905 { 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); for (i=0;i ( 0, x.Length, () => 0, (j, loop, subtotal) => { subtotal += x[j]; return subtotal; }, (xx) => Interlocked.Add(ref total, xx) ); Console.Write("Parallel summation"); t4=sw.ElapsedMilliseconds / 1000.0; t5=t4-t3; Console.WriteLine(" {0,5:0.000}",t5); if ( n != total ) Console.WriteLine( "Error in summation \n Total = {0:N0}", total); total=0; for(i=0;i