Must I destroy the local matrix I have (created and) set with MatISSetLocalMat ?
Must I destroy the local matrix I have (created and) set with MatISSetLocalMat ? Franck
On Tue, May 30, 2017 at 2:21 AM, Franck Houssen <[email protected]> wrote:
Must I destroy the local matrix I have (created and) set with MatISSetLocalMat ?
Yes. Matt
Franck
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener http://www.caam.rice.edu/~mk51/
Franck Houssen <[email protected]> writes:
Must I destroy the local matrix I have (created and) set with MatISSetLocalMat ?
The implementation references the local matrix so you need to destroy your copy. This pattern is always used when setting sub-objects like this. static PetscErrorCode MatISSetLocalMat_IS(Mat mat,Mat local) { Mat_IS *is = (Mat_IS*)mat->data; PetscInt nrows,ncols,orows,ocols; PetscErrorCode ierr; PetscFunctionBegin; if (is->A) { ierr = MatGetSize(is->A,&orows,&ocols);CHKERRQ(ierr); ierr = MatGetSize(local,&nrows,&ncols);CHKERRQ(ierr); if (orows != nrows || ocols != ncols) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"Local MATIS matrix should be of size %Dx%D (you passed a %Dx%D matrix)",orows,ocols,nrows,ncols); } ierr = PetscObjectReference((PetscObject)local);CHKERRQ(ierr); ierr = MatDestroy(&is->A);CHKERRQ(ierr); is->A = local; PetscFunctionReturn(0); }
participants (3)
-
Franck Houssen -
Jed Brown -
Matthew Knepley