title: The cost of performing analyzePattern() and factorize() in Eigen library Compute()
body: <p>I am referring to the <a href="https://eigen.tuxfamily.org/dox-devel/group__TopicSparseSystems.html" rel="nofollow noreferrer">The Compute Step</a> section in Eigen documentation:</p>
  
  <blockquote>
    <p>In the <code>compute()</code> function, the matrix is generally factorized: </p>
    
    <p>....</p>
    
    <p>For this class of solvers precisely,
    the compute step is further subdivided into <code>analyzePattern()</code> and
    <code>factorize()</code>.</p>
    
    <p>The goal of <code>analyzePattern()</code> is to reorder the nonzero elements of the
    matrix, such that the factorization step creates less fill-in. This
    step exploits only the structure of the matrix. <strong>Hence, the results of
    this step can be used for other linear systems where the matrix has
    the same structure.</strong> ....</p>
    
    <p>In <code>factorize()</code>, the factors of the coefficient matrix are computed.
    This step should be called each time the values of the matrix change.
    <strong>However, the structural pattern of the matrix should not change
    between multiple calls.</strong></p>
  </blockquote>
  
  <p>The documentation for  <a href="https://eigen.tuxfamily.org/dox-devel/classEigen_1_1SparseLU.html#aa907ff958c4f4855145091d2686f3a8a" rel="nofollow noreferrer">analyzePattern()</a> </p>
  
  <blockquote>
    <p>Compute the column permutation to minimize the fill-in</p>
    
    <ul>
    <li>Apply this permutation to the input matrix -</li>
    <li>Compute the column elimination tree on the permuted matrix</li>
    <li>Postorder the elimination tree and the column permutation</li>
    </ul>
  </blockquote>
  
  <p>and <a href="https://eigen.tuxfamily.org/dox-devel/classEigen_1_1SparseLU.html#a39858b0e72f2659d596364e252b34cbc" rel="nofollow noreferrer">factorize()</a></p>
  
  <blockquote>
    <p>Numerical factorization Interleaved with the symbolic factorization On
    exit, info is</p>
    
    <p>= 0: successful factorization</p>
    
    <p>0: if info = i, and i is</p>
    
    <p>&lt;= A->ncol: U(i,i) is exactly zero. The factorization has
         been completed, but the factor U is exactly singular,
         and division by zero will occur if it is used to solve a
         system of equations.</p>
    
    <blockquote>
      <p>A->ncol: number of bytes allocated when memory allocation
          failure occurred, plus A->ncol. If lwork = -1, it is
          the estimated amount of space needed, plus A->ncol.</p>
    </blockquote>
  </blockquote>
  
  <p>My question is, do we know the relative cost of calling <code>analyzePattern()</code> and  <code>factorize()</code>? </p>
  
  <p>This question is important to me because my application has a stable matrix structure but constantly changing coefficient matrix. Example: in FEM model, FEM users often leave the element connection unchanged, but always change the element sizes in order to get the best design. </p>
  
  <p>So if <code>analyzePattern()</code> is a lot expensive than <code>factorize()</code>, then I can take advantage of this fact and rewrite my code. If no, I can just stick to the <code>compute()</code> function and rerun <code>analyzePattern()</code> every time the element sizes change. </p>