The memory issue you're experiencing likely stems from the demands of solving a large sparse linear system in MATLAB. Here's breakdown:
- Matrix Size and Operations: Although your sparse matrix 'M' has 10 billion elements with only 499,987 non-zero elements, certain operations may inadvertently convert parts of the matrix to a dense format, increasing memory usage. Specifically, solving the system (I - p*G*D)\e can be problematic. While (G) and (D) are sparse, the resulting matrix (I - p*G*D) might not remain sparse during factorization.
- LU Factorization: The backslash operator (\backslash) in MATLAB typically involves LU factorization, which can introduce significant fill-in, making the LU factors denser than the original sparse matrix and thus consuming more memory.
- Memory Overhead: Additional memory is needed for temporary variables, the solution vector, and managing sparse matrix operations, contributing to the increased memory demand.
Some recommendations that might help in resolving the issue is:
- For large sparse systems, consider using iterative solvers like “pcg” (Preconditioned Conjugate Gradient) or “gmres” with appropriate preconditioning. These methods generally use less memory than direct solvers like LU factorization.
- Use MATLAB's memory profiling tools to identify where the most memory is being used. This can help pinpoint operations that cause excessive memory usage.
- If possible, adjust the damping factor “p” and the structure of G to see if that impacts memory usage.
For detailed understanding of “pcg” and “gmres”, as well as MATLAB’s memory profiling tool please refer to following documentation:
Hope that helps!.