wrtobin / las

Zero-overhead interfaces to Linear Algebraic data structures and Solvers
1 stars 1 forks source link

Sparsity lifetime #19

Open wrtobin opened 6 years ago

wrtobin commented 6 years ago

A sparsity is allocated inside of las and used to create a matrix of some type.

The matrix will then either own the sparsity and manage it's lifespan or the sparsity is still owned by the user and must be dealt with.

At present this detail is handled differently by different backends. When creating a PETSc matrix, the Sparsity NNZ is used to preallocate the matrix, but not owned by the PETSc Mat.

The sparse sparse(csr) backend captures the underlying CSR object, but doesn't own it since the object is not deleted when the matrix is. But if the user deletes the CSR object in user space the matrix would be invalidated.

We either need to copy the CSR (less desirable but not practically terrible), or invalidate the user-space pointer to the Sparsity so the user can't accidentally delete it and invalidate the Matrix, which would mean passing in a Sparsity * to the matrix creation function instead of a Sparsity.

wrtobin commented 6 years ago

Also in the dense backend the Sparsity is used but not captured so the object doesn't need to persist and the user should immediately delete it . Basically the usage needs to be standardized across the board.

wrtobin commented 6 years ago

Added the ability to specify csr ownership in the csrMat constructor in commit 3ee26dd3ae428359eaddad319ff949152ea733b7, but usage of this additional interface facility isn't ubiquitous or consistent yet.