- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够在 C# 中求解大型稀疏 线性方程组(dim = 1,000,000)。为此,我将 Math.NET Numerics 与 MKL 提供程序结合使用。
我创建了以下测试程序来检查 Math.NET Numerics 的性能,但是,即使对于 int dim = 5000;
,该程序也需要很长时间才能等待运行结束。另外,我的机器的 cpu 使用率没有超过 25%(机器有 4 个内核)。
将 MKL 与 Fortran 结合使用,我可以更快地解决更大的系统 (dim = 1,000,000)(CPU 使用率接近 100%)。我正在使用直接稀疏求解器 (DSS) 接口(interface)例程。
using MathNet.Numerics;
using MathNet.Numerics.LinearAlgebra;
namespace ConsoleApp1
{
class Program
{
static void Main()
{
Control.UseNativeMKL();
Control.UseMultiThreading();
int dim = 5000;
var A = Matrix<double>.Build.Sparse(dim, dim);
var F = Vector<double>.Build.Dense(dim);
for (int i = 0; i < dim; i++)
{
A[i, i] = 1.0;
F[i] = 1.0;
}
// THIS TAKES FOREVER
Vector<double> X = A.Solve(F);
}
}
}
我可以做些什么来提高上述程序的性能?
更新
尽管 ALGLIB 免费版确实有一些限制:
First limitation is performance. Free Editions do not include multithreading functionality, SIMD optimizations, native HPC kernelsfor C# apps and integration with Intel MKL.
Second limitation is license. Our flagship products (ALGLIB for C++ and ALGLIB for C#) are distributed under GPL 2+ license, which isnot suited for commercial distribution; other products are distributedunder Personal and Academic Use License.
它在解决稀疏系统方面确实提供了更好的性能(与 Math.Net Numerics 相比)。它还确实提供了处理稀疏矩阵的便捷方法。
最佳答案
根据 this comment一年半之前 Math.Net 中没有稀疏矩阵的直接求解器。
I believe Math.Net doesn't provide any direct solvers for sparse matrices. It will try to solve it as a dense matrix which will take a very long time. I use CSparse.Net for sparse matrices (https://github.com/wo80/CSparse.NET/wiki/Math.NET-Numerics-and-CSparse)
以下注释来自 an article八岁以某种方式证实了这一点:
The examples so far used only dense vectors and matrices. Math.NET Numerics provides types SparseVector and SparseMatrix and has a good design for future support for working with them. However, the current implementation for them is very limited. For instance, the types do not have a constructor to build a sparse vector using indexed non-zero values. Very few math libraries provide full support for sparse matrices and sparse linear algebra because there is no clear standard for sparse matrix linear algebra (unlike BLAS/LAPACK for dense matrices)
我浏览了库代码的相关部分,没有找到任何直接的稀疏矩阵求解器。
关于c# - Math.NET Numerics 性能不佳且 CPU 使用率低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57644573/
我是一名优秀的程序员,十分优秀!