using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace GraphEdgeCount { class Program { static int MatrixSize = 10000; static bool[,] Matrix = new bool[10000,10000]; static int Edges=0; static Semaphore semaphoreObject = new Semaphore(initialCount: 1, maximumCount: 1, name: "Edge"); static void FillMatrix() { Random c = new Random(); for(int i=0;i threadList = new List(); // DisplayMatrix(); Stopwatch parallel = new Stopwatch(); Stopwatch seq = new Stopwatch(); parallel.Start(); for (int i=0;i CountEdgesFromNode(n)); t.Start(); threadList.Add(t); } foreach (var t in threadList) t.Join(); parallel.Stop(); Console.WriteLine("{0} Edges counted in parallel, it took {1}",Edges, parallel.Elapsed); Edges = 0; seq.Start(); CountAllEdges(); seq.Stop(); Console.WriteLine("{0} Edges counted sequentially, it took {1}", Edges, seq.Elapsed); } } }