【发布时间】:2013-10-12 18:28:07
【问题描述】:
我正在使用 Boost UBlas 的数值库绑定来解决一个简单的线性系统。 以下工作正常,除了它仅限于处理矩阵 A(m x m) 相对 小“m”。
实际上,我有一个更大的矩阵,尺寸 m= 10^6(最多 10^7)。
是否存在有效使用内存的解决 Ax=b 的现有 C++ 方法。
#include<boost/numeric/ublas/matrix.hpp>
#include<boost/numeric/ublas/io.hpp>
#include<boost/numeric/bindings/traits/ublas_matrix.hpp>
#include<boost/numeric/bindings/lapack/gesv.hpp>
#include <boost/numeric/bindings/traits/ublas_vector2.hpp>
// compileable with this command
//g++ -I/home/foolb/.boost/include/boost-1_38 -I/home/foolb/.boostnumbind/include/boost-numeric-bindings solve_Axb_byhand.cc -o solve_Axb_byhand -llapack
namespace ublas = boost::numeric::ublas;
namespace lapack= boost::numeric::bindings::lapack;
int main()
{
ublas::matrix<float,ublas::column_major> A(3,3);
ublas::vector<float> b(3);
for(unsigned i=0;i < A.size1();i++)
for(unsigned j =0;j < A.size2();j++)
{
std::cout << "enter element "<<i << j << std::endl;
std::cin >> A(i,j);
}
std::cout << A << std::endl;
b(0) = 21; b(1) = 1; b(2) = 17;
lapack::gesv(A,b);
std::cout << b << std::endl;
return 0;
}
【问题讨论】:
-
指出显而易见的,一个矩阵大小为 4x10^12 到 4x10^14 字节,或者单独一个矩阵为 4 到 400 TB。 (除非,如下所述,它的稀疏)
标签: c++ boost linear-algebra lapack umfpack