Since the process of dynamic memory allocation for sparse matrices is inherently very expensive, accurate preallocation of memory is crucial for efficient sparse matrix assembly. One should use the matrix creation routines for particular data structures, such as MatCreateSeqAIJ() and MatCreateMPIAIJ() for compressed, sparse row formats, instead of the generic MatCreate() routine. For problems with multiple degrees of freedom per node, the block, compressed, sparse row formats, created by MatCreateSeqBAIJ() and MatCreateMPIBAIJ(), can significantly enhance performance. Section Sparse Matrices includes extensive details and examples regarding preallocation.