How to copy global data to local ?

Barry Smith bsmith at mcs.anl.gov
Tue Dec 1 23:46:03 CST 2009


    Don't know what MatGetSubMatrixRaw() is, but based on the calling  
sequence you are asking for the ith row whatever that is, and n  
columns in the array indices

    For MatGetSubMatrix() each process can ask for any rows it wants,  
but all the processors have to ask for the same columns that are wanted.

    Barry

On Dec 1, 2009, at 9:59 PM, ming zhu wrote:

> Hi
> I tried MatGetSubMatrix() but I am a little confused by the column  
> parameter. For example
> My matrix is U (m * n). I want to get i,j rows to local.
> my code is
>
> PetscInt* rowindex,colindex;
> PetscMalloc...
> for (k= 0; k < n; k++)
>    colindex[k] = k;
>
> rowindex[0] = i;
> rowindex[1] = j;
>
> MatGetSubMatrixRaw(U,1,&i,n,indices,n,MAT_INITIAL_MATRIX,&newmat);
>
> What I hope is newmat is 2 * n matrix. But I failed.
>
> Thank you
>
>
> --- 09年12月1日,周二, Barry Smith <bsmith at mcs.anl.gov> 写 
> 道:
>
> 发件人: Barry Smith <bsmith at mcs.anl.gov>
> 主题: Re: How to copy global data to local ?
> 收件人: "PETSc users list" <petsc-users at mcs.anl.gov>
> 日期: 2009年12月1日,周二,下午10:35
>
>
>    You misunderstand the usage of MatGetSubMatrix(). Any process can  
> request ANY row, including rows that are not originally owned by  
> that process.
>
>    Barry
>
> On Dec 1, 2009, at 8:29 AM, ming zhu wrote:
>
> > It seems that MatGetSubMatrix() only get the local matrix for the  
> processor  If U is global(PETSC_COMM_WORLD), the local matrix may  
> not store the column or row I wanted. For example, if U is 4*4, and  
> there are 4 processors, processors one has local matrix 2*2, but i  
> need the third row, Then,MatGetSubmatrix() may not work
> >
> > --- 09年12月1日,周二, Barry Smith <bsmith at mcs.anl.gov> 写 
> 道:
> >
> > 发件人: Barry Smith <bsmith at mcs.anl.gov>
> > 主题: Re: How to copy global data to local ?
> > 收件人: "PETSc users list" <petsc-users at mcs.anl.gov>
> > 日期: 2009年12月1日,周二,下午10:23
> >
> >
> > On Nov 30, 2009, at 11:21 PM, ming zhu wrote:
> >
> > > Hi
> > > I have a huge matrix U for all processors (PETSC_COMM_WORLD). I  
> only want to copy only two rows (i,j) for each local processor. i,j  
> is different for each processor and not related to rank.  I was  
> trying to use a vector filter (like, 00000010000). However, if the  
> vector is PETSC_COMM_WORLD, it will be changed by different  
> processor. So, how to make it ?
> > 
>                                                                                                                                                                           ^ 
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> >    I do not understand what this means. To do the multiply you can  
> and should use a vector of PETSC_COMM_WORLD.
> >
> >    Also multiplying by a vector will not give you back "rows" of a  
> matrix. Do you truly want the entire row of nonzeros of the matrix  
> or something else. If you want the entire row or part of a row then  
> you can use MatGetSubMatrix().
> >
> >    Barry
> >
> > > Thank you
> > >
> > > My original code is
> > >
> > > Vec filter
> > > VecCreate(PETSC_COMM_WORLD,&filter);
> > > VecSetsizes(filter,PETSC_DECIDE,m);
> > > VecSetFromOptions(filter);
> > >
> > > Vecset(filter,0);
> > > VecSetValue(filter,i,1,INSERT_VALUES);
> > >
> > > ...
> > > MatMult(U, filter,ui);
> > >
> > > If I create filter with PETSC_COMM_SELF, it is impossible for U  
> and filter to multiply.
> > >
> > >
> > >
> > >
> > >
> > > 好玩贺卡等你发,邮箱贺卡全新上线!
> >
> >
> > 好玩贺卡等你发,邮箱贺卡全新上线!
>
>
> 好玩贺卡等你发,邮箱贺卡全新上线!



More information about the petsc-users mailing list