How important is the accurate specification of nnz for spalloc?

2 次查看(过去 30 天)
How important for performance is the accurate specification of nnz for spalloc? And is undershooting worse than overshooting?

采纳的回答

James Tursa
James Tursa 2017-7-22
编辑:James Tursa 2017-7-22
In general, undershooting is much worse than overshooting. With undershooting, if you go over the allocated amount by even 1 element, the entire data blocks (value & indexing) must be copied over into newly allocated data blocks. But if you overshoot by 1 element, you simply have a few bytes of extra storage allocated and it will not impact performance at all. As to how bad the undershooting will hurt you, that will depend entirely on how large those data blocks are and how often you end up copying them to newly allocated memory blocks.
  2 个评论
Ulrik William Nash
Ulrik William Nash 2017-7-22
Thank you, James, for this answer. This will help me quite a bit, I think.
James Tursa
James Tursa 2017-7-22
FYI, if you add in one element beyond current capacity, MATLAB does not allocate room for just one more element ... it is smarter than that. It will allocate more space using an internal formula based on the current size of the blocks. But still, it is best to limit how often this happens if you can.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by