- Using a preconditioner can speed up convergence and help reduce the number of iterations required, thereby reducing memory required.
- Another approach to reduce memory usage is to use the gmres implementation with r restarts would require less memory to store intermediate vectors and matrices compared to the default implementation. You could use this input along with the maxit input to control the maximum number of iterations.
Out of memory error using gmres in while loop
4 次查看(过去 30 天)
显示 更早的评论
Hello all,
I am solving a system of non-linear PDEs using Newton's method. Essentially, I obtain a jacobian block tridiagonal matrix and solve it with gmres which produces a solution vector somewhat more precise than the previous iteration. This sequence iterates within a while loop until some convergence criteria is met. The code runs successfully, however the memory usage in task manager/activity monitor continues increasing until it reaches 98%, at which point matlab produces an "out of memory" error and crashes. I am wondering how to fix this.
My main point of confusion as to why this is happeneing is that I am not intensionally creating new variables during iteration. All arrays stay the same size and are overwritten each iteration so I would expect the memory usage to stay approximately constant. Instead, the memory used by matlab increases with runtime. I have tried clearing the jacobian each iteration, in addition to some smaller arrays, which did not help. I am wondering if gmres allocates memory somewhere within it's nested functions (which I don't see because it is not in the workspace) and then does not clear it. This might explain why a memory usage build up occurs.
Any comments or suggestions are appreciated.
Thanks
0 个评论
回答(1 个)
Sourabh
2023-5-19
Greetings Wes,
There are a few things I can think of to try and reduce the memory consumption when using the gmres function:
It is also possible that the issue is not related to gmres, but rather to some other part of your code or any external functions you might be calling.
Also, you might find the following links useful:
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!