title: C++ Memory Efficient Solution for Ax=b Linear Algebra System
body: <p>I am using Numeric Library Bindings for Boost UBlas to solve a simple linear system.
  The following works fine, except it is limited to handling matrices A(m x m) for relatively
  small 'm'.</p>
  
  <p>In practice I have a much larger matrix with dimension m= 10^6 (up to 10^7).<br>
  Is there existing C++ approach for solving Ax=b that uses memory efficiently.</p>
  
  <pre><code>#include&lt;boost/numeric/ublas/matrix.hpp&gt;
  #include&lt;boost/numeric/ublas/io.hpp&gt;
  #include&lt;boost/numeric/bindings/traits/ublas_matrix.hpp&gt;
  #include&lt;boost/numeric/bindings/lapack/gesv.hpp&gt;
  #include &lt;boost/numeric/bindings/traits/ublas_vector2.hpp&gt;
  
  // 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&lt;float,ublas::column_major&gt; A(3,3);
      ublas::vector&lt;float&gt; b(3);
  
  
      for(unsigned i=0;i &lt; A.size1();i++)
          for(unsigned j =0;j &lt; A.size2();j++)
          {
              std::cout &lt;&lt; "enter element "&lt;&lt;i &lt;&lt; j &lt;&lt; std::endl;
              std::cin &gt;&gt; A(i,j);
          }
  
      std::cout &lt;&lt; A &lt;&lt; std::endl;
  
      b(0) = 21; b(1) = 1; b(2) = 17;
  
      lapack::gesv(A,b);
  
      std::cout &lt;&lt; b &lt;&lt; std::endl;
  
  
      return 0;
  }
  </code></pre>