예제 #1
0
        public void Should_solve_tridiagonal_matrix_system()
        {
            var a = MatrixMarketReader.ReadMatrix <double>("matrix1.mtx");
            var b = MatrixMarketReader.ReadVector <double>("vector1.mtx");

            var result = GmresSolver.Solve(a, b, 15, 1);

            result.IsConverged.Should().BeTrue();
            result.OuterIterations.Should().Be(0);
            result.InnerIterations.Should().Be(11);
            foreach (var xValue in result.X)
            {
                xValue.Should().BeApproximately(1.0, GmresSolver.DefaultEpsilon);
            }
        }
예제 #2
0
        public void Should_solve_dense_matrix_system()
        {
            var a = MatrixMarketReader.ReadMatrix <double>("matrix2.mtx");
            var b = MatrixMarketReader.ReadVector <double>("vector2.mtx");

            var result = GmresSolver.Solve(a, b);

            result.IsConverged.Should().BeTrue();
            result.OuterIterations.Should().Be(0);
            result.InnerIterations.Should().Be(6);

            var expectedX = new[] { -4.0306249, 3.3608880, 3.8133424, -1.0654047, 3.4175426, -2.0298796 };

            for (var i = 0; i < expectedX.Length; i++)
            {
                result.X[i].Should().BeApproximately(expectedX[i], GmresSolver.DefaultEpsilon);
            }
        }
예제 #3
0
        public static void Execute(Options options)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            Console.WriteLine($"Reading from {options.InputMatrixFileName}...");
            var a = MatrixMarketReader.ReadMatrix <double>(options.InputMatrixFileName);

            Console.WriteLine($"Reading from {options.InputVectorFileName}...");
            var b = MatrixMarketReader.ReadVector <double>(options.InputVectorFileName);

            Console.WriteLine("Start solving...");
            var result = GmresSolver.Solve(a, b, options.MaxInnerIterations, options.MaxOuterIterations, options.Epsilon, degreeOfParallelism: options.DegreeOfParallelism);

            Console.WriteLine($"Finished. IsConverged = {result.IsConverged}. Last error: {result.Errors.Last()}");
            Console.WriteLine($"Performed {result.InnerIterations} inner iterations and {result.OuterIterations} outer iterations");

            Console.WriteLine($"Writing solution to {options.OutputFileName}...");
            MatrixMarketWriter.WriteVector(options.OutputFileName, result.X);

            Console.WriteLine($"Total execution time, ms: {stopwatch.Elapsed.TotalMilliseconds}");
        }