How important is the accurate specification of nnz for spalloc?

4 vues (au cours des 30 derniers jours)
Ulrik William Nash
Ulrik William Nash le 22 Juil 2017
Commenté : James Tursa le 22 Juil 2017
How important for performance is the accurate specification of nnz for spalloc? And is undershooting worse than overshooting?

Réponse acceptée

James Tursa
James Tursa le 22 Juil 2017
Modifié(e) : James Tursa le 22 Juil 2017
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 commentaires
Ulrik William Nash
Ulrik William Nash le 22 Juil 2017
Thank you, James, for this answer. This will help me quite a bit, I think.
James Tursa
James Tursa le 22 Juil 2017
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Sparse Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by