[petsc-users] Local and global size of IS
Matthew Knepley
knepley at gmail.com
Wed Mar 27 07:48:35 CDT 2019
On Wed, Mar 27, 2019 at 8:33 AM Eda Oktay via petsc-users <
petsc-users at mcs.anl.gov> wrote:
> Hello,
>
> I am trying to permute a matrix A(of size 2n*2n) according to a sorted
> eigenvector vr (of size 2n) in parallel using 2 processors (processor
> number can change). However, I get an error in MatPermute line stating that
> arguments are out of range and a new nonzero caused a malloc even if I used
> MatSetOption.
>
> I discovered that this may be because of the unequality of local sizes of
> is (and newIS) and local size of A.
>
> Since I allocate index set idx according to size of the vector vr, global
> size of is becomes 2n and the local size is also 2n (I think it should be n
> since both A and vr has local sizes n because of the number of processors).
> If I change the size of idx, then because of VecGetArrayRead, I think is is
> created wrongly.
>
> So, how can I make both global and local sizes of is,newIS and A?
>
> Below, you can see the part of my program.
>
> Thanks,
>
> Eda
>
> ierr = VecGetSize(vr,&siz);CHKERRQ(ierr);
>
Here siz is the length of the parallel Vec.
> ierr = PetscMalloc1(siz,&idx);CHKERRQ(ierr);
> for (i=0; i<siz;i++) idx[i] = i;
> ierr = VecGetArrayRead(vr,&avr);CHKERRQ(ierr);
> ierr = PetscSortRealWithPermutation(siz,avr,idx);CHKERRQ(ierr);
>
> ierr =
> ISCreateGeneral(PETSC_COMM_SELF,siz,idx,PETSC_COPY_VALUES,&is);CHKERRQ(ierr);
>
Here siz is the length of the _serial_ IS. You want the local size of the
Vec here.
Matt
> ierr = ISSetPermutation(is);CHKERRQ(ierr);
> ierr = ISDuplicate(is,&newIS);CHKERRQ(ierr);
> MatSetOption(A,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_FALSE);CHKERRQ(ierr);
> ierr = MatPermute(A,is,newIS,&PL);CHKERRQ(ierr);
>
--
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
https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190327/b99cd988/attachment.html>
More information about the petsc-users
mailing list