[petsc-users] When to destroy an IS?

Florian Lindner mailinglists at xgm.de
Wed Feb 24 09:58:52 CST 2016


Hello,

I create a couple of index sets:

  ISLocalToGlobalMapping _ISmapping;
  IS ISlocal, ISlocalInv, ISglobal, ISidentity, ISidentityGlobal;
  ISLocalToGlobalMapping ISidentityMapping;

  // Create an index set which maps myIndizes to continous chunks of matrix rows.
  ierr = ISCreateGeneral(PETSC_COMM_WORLD, myIndizes.size(), myIndizes.data(), PETSC_COPY_VALUES, &ISlocal); CHKERRV(ierr);
  ierr = ISSetPermutation(ISlocal); CHKERRV(ierr);
  ierr = ISInvertPermutation(ISlocal, myIndizes.size(), &ISlocalInv); CHKERRV(ierr);
  ierr = ISAllGather(ISlocalInv, &ISglobal); CHKERRV(ierr); // Gather the IS from all processors
  ierr = ISLocalToGlobalMappingCreateIS(ISglobal, &_ISmapping); CHKERRV(ierr); // Make it a mapping
  
  // Create an identity mapping and use that for the rows of matrixA.
  ierr = ISCreateStride(PETSC_COMM_WORLD, _matrixA.ownerRange().second - _matrixA.ownerRange().first, _matrixA.ownerRange().first, 1, &ISidentity); CHKERRV(ierr);
  ierr = ISSetIdentity(ISidentity); CHKERRV(ierr);
  ierr = ISAllGather(ISidentity, &ISidentityGlobal); CHKERRV(ierr);
  ierr = ISLocalToGlobalMappingCreateIS(ISidentityGlobal, &ISidentityMapping); CHKERRV(ierr);

  ierr = MatSetLocalToGlobalMapping(_matrixC.matrix, _ISmapping, _ISmapping); CHKERRV(ierr); // Set mapping for rows and cols
  ierr = MatSetLocalToGlobalMapping(_matrixA.matrix, ISidentityMapping, _ISmapping); CHKERRV(ierr); // Set mapping only for cols, use identity for rows


Two questions:

1) Since I only need the _ISmapping again, is there any way to optimize that, i.e. use less temporary variables?
2) Do all IS variables (_ISmapping, ISlocal, ISlocalInv, ISglobal, ISidentity, ISidentityGlobal, ISidentityMapping) need to be destroyed using ISDestroy at the end? Or only the ones that were created using a ISCreate* function (ISlocal, ISidentity)?

Thanks,

Florian


More information about the petsc-users mailing list