예제 #1
0
        public Board ParallelIterationRun(Board old, int numberOfThreads, bool verbose = false)
        {
            var sw = new Stopwatch();

            sw.Start();
            var newBoard = CopyOld(old);


            var options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = numberOfThreads
            };

            Parallel.For(0, old.Width, options, i =>
            {
                Parallel.For(0, old.Height, options, j =>
                {
                    newBoard.Population[i, j] = NextStateController.NextState(i, j, old);
                    if (verbose)
                    {
                        Console.WriteLine($"{i} {j} - {Thread.CurrentThread.ManagedThreadId}");
                    }
                });
            });

            sw.Stop();
            Console.WriteLine("Elapsed={0}, migration={1}", sw.Elapsed, Board.Migration);
            return(newBoard);
        }
예제 #2
0
        public Board SequentialIterationRun(Board old, bool verbose = false)
        {
            var sw = new Stopwatch();

            sw.Start();
            var newBoard = CopyOld(old);

            for (int i = 0; i < old.Width; i++)
            {
                for (int j = 0; j < old.Height; j++)
                {
                    newBoard.Population[i, j] = NextStateController.NextState(i, j, old);
                    if (verbose)
                    {
                        Console.WriteLine($"{i} {j} - {Thread.CurrentThread.ManagedThreadId}");
                    }
                }
            }
            sw.Stop();
            Console.WriteLine("Elapsed={0}, migration={1}", sw.Elapsed, Board.Migration);
            return(newBoard);
        }