Re: [petsc-users] When to destroy an IS?

2016-02-24 Thread Matthew Knepley
On Wed, Feb 24, 2016 at 9:58 AM, Florian Lindner 
wrote:

> 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, ); CHKERRV(ierr);
>   ierr = ISSetPermutation(ISlocal); CHKERRV(ierr);
>   ierr = ISInvertPermutation(ISlocal, myIndizes.size(), );
> CHKERRV(ierr);
>   ierr = ISAllGather(ISlocalInv, ); 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, );
> CHKERRV(ierr);
>   ierr = ISSetIdentity(ISidentity); CHKERRV(ierr);
>   ierr = ISAllGather(ISidentity, ); CHKERRV(ierr);
>   ierr = ISLocalToGlobalMappingCreateIS(ISidentityGlobal,
> ); 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?
>

It is not clear to me what is being done.


> 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)?
>

All of them since you create new ISes with all those functions like
ISInvertPermutation.

  Matt


> Thanks,
>
> Florian
>



-- 
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


[petsc-users] When to destroy an IS?

2016-02-24 Thread Florian Lindner
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, ); CHKERRV(ierr);
  ierr = ISSetPermutation(ISlocal); CHKERRV(ierr);
  ierr = ISInvertPermutation(ISlocal, myIndizes.size(), ); 
CHKERRV(ierr);
  ierr = ISAllGather(ISlocalInv, ); 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, ); 
CHKERRV(ierr);
  ierr = ISSetIdentity(ISidentity); CHKERRV(ierr);
  ierr = ISAllGather(ISidentity, ); CHKERRV(ierr);
  ierr = ISLocalToGlobalMappingCreateIS(ISidentityGlobal, ); 
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