Example #1
0
        static async Task MainAsync()
        {
            Console.WriteLine("Please, choose option");
            Console.WriteLine("Press 1 to compare multipliers time of work on different number of threads and constant matrix size");
            Console.WriteLine("Press 2 to compare multipliers time of work on different matrix sizes");
            Console.WriteLine("Press any key to perform matrix multiplication");

            var choice = Console.ReadLine();

            switch (choice)
            {
            case "1":
                CompareTimeOfWorkOnConstantMatrixSize();
                break;

            case "2":
                CompareTimeOfWorkDependingOnMatrixSize();
                break;
            }

            Console.WriteLine("Enter path to file with left matrix");
            var pathLeft = Console.ReadLine();

            Console.WriteLine("Enter path to file with right matrix");
            var pathRight = Console.ReadLine();

            Console.WriteLine("Enter path to file, where result will be written");
            var resultPath = Console.ReadLine();

            int[,] left, right;
            try
            {
                var fileReader = new MatrixFileReader();
                left = await fileReader.ReadAsync(pathLeft);

                right = await fileReader.ReadAsync(pathRight);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            Console.WriteLine("\nChoose type of multiplier");
            Console.WriteLine("1 - Synchronous Matrix Multiplier");
            Console.WriteLine("2 - Parallel.For Matrix Multiplier");
            Console.WriteLine("3 - Striped Parallelizing Matrix Multiplier");
            Console.WriteLine("4 - Sequentially Parallelizing Matrix Multiplier");
            Console.WriteLine("Press any key to exit");

            choice = Console.ReadLine();
            IMatrixMultiplier multiplier = choice switch
            {
                "1" => new SynchronousMatrixMultiplier(),
                "2" => new ParallelForMatrixMultiplier(),
                "3" => new StripedParallelizingMatrixMultiplier(),
                "4" => new SequentiallyParallelizingMatrixMultiplier(),
                _ => null
            };

            if (multiplier == null)
            {
                return;
            }

            Console.WriteLine("Multiplying performs...");
            try
            {
                var result     = multiplier.Multiply(left, right);
                var fileWriter = new MatrixFileWriter();
                await fileWriter.WriteAsync(result, resultPath);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            Console.WriteLine("Ready!");
        }
    }
Example #2
0
 public void Setup()
 {
     fileWriter = new MatrixFileWriter();
     fileReader = new MatrixFileReader();
 }