<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br><br>--- <b>09年12月2日,周三, ming zhu <i><foolishzhu@yahoo.com.cn></i></b> 写道:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>发件人: ming zhu <foolishzhu@yahoo.com.cn><br>主题: Re: How to copy global data to local ?<br>收件人: "petsc-maint Maintenance" <petsc-maint@mcs.anl.gov><br>日期: 2009年12月2日,周三,下午10:32<br><br><div id="yiv1172394382"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit; -x-system-font: none;" valign="top">Sorry. OK<br>The problem is <br>if I use <br>// n is 5 the total column number for U<br>ierr = MatGetSubMatrix(U,ix,iy,n,
MAT_INITIAL_MATRIX,&ui);CHKERRQ(ierr);<br> <br>when I run mpiexec -np 2 ./program<br>it reports <br>Sum of local lengths 10 does not equal global length 5, my local length 5<br><br>if I use <br>ierr = MatGetSubMatrix(U,ix,iy,PETSC_DECIDE, MAT_INITIAL_MATRIX,&ui);CHKERRQ(ierr);<br><br>it reports<br>Only local values currently supported!<br><br>--- <b>09年12月2日,周三, Barry Smith <i><bsmith@mcs.anl.gov></i></b> 写道:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>发件人: Barry Smith <bsmith@mcs.anl..gov><br>主题: Re: How to copy global data to local ?<br>收件人: "PETSc users list" <petsc-users@mcs.anl.gov>, "petsc-maint Maintenance"
<petsc-maint@mcs.anl.gov><br>日期: 2009年12月2日,周三,下午3:52<br><br><div class="plainMail"><br> Let's move this over to <a rel="nofollow">petsc-maint@mcs.anl.gov</a> to cut the traffic on petsc-users See below.<br>On Dec 2, 2009, at 12:33 AM, ming zhu wrote:<br><br>> OK. I am now use MatGetSubMatrix.My code is as follows<br>> <br>> PetscMalloc(n*sizeof(PetscInt),&indices);<br>> for (j = 0; j < n; j++)<br>> {<br>> indices[j] = j;<br>> }<br>> ISCreateGeneral(PETSC_COMM_SELF,n,indices,&iy); // get all columns<br>> .....<br>> <br>> PetscMalloc(2*sizeof(PetscInt),&indices);<br>> indices[0] = i;<br>> indices[1] = j;<br>>
ISCreateGeneral(PETSC_COMM_SELF,2,indices,&ix); // only get i,j rows<br>> <br>> Mat ui,uj;<br>> // I am not sure how to set the third parameter : how many "local " columns. Since I want all columns, I set it to n<br>> ierr = MatGetSubMatrix(U,ix,iy,n, MAT_INITIAL_MATRIX,&ui);CHKERRQ(ierr);<br>> <br>> What I really hope is to<br>> <br>> for (i = 0; i < n; i++)<br>> {<br>> PetscInt row = 0;<br>> MatGetValues(ui,1,&row,1,&i,&u_ik);<br>> }<br>> It does not work. I tried to change the n to PETSC_DECIDE, it still does not work<br> ^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^<br><br> Saying "it does not work" is extremely uninformative and makes it difficult for us to know what happened and thus make useful suggestions. Please say exactly what goes wrong and cut and paste all error messages. At this point we would be totally guessing what is happening.<br><br> Barry<br><br>> <br>> So, I really doubt that whether I can get the entire row of the matrix.<br>> <br>> BTW, the matrix is created as follows:<br>> MatCreateMPIDense(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_NULL,&U)<br>> <br>> THank you<br>> --- 09年12月2日,周三, Barry Smith <<a rel="nofollow">bsmith@mcs.anl.gov</a>> 写道:<br>>
<br>> 发件人: Barry Smith <<a rel="nofollow">bsmith@mcs.anl.gov</a>><br>> 主题: Re: How to copy global data to local ?<br>> 收件人: "PETSc users list" <<a rel="nofollow">petsc-users@mcs.anl.gov</a>><br>> 日期: 2009年12月2日,周三,下午1:46<br>> <br>> <br>> 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<br>> <br>> 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.<br>> <br>> Barry<br>> <br>> On Dec 1, 2009, at 9:59 PM, ming zhu wrote:<br>> <br>> > Hi<br>> > I tried MatGetSubMatrix() but I am a little confused
by the column parameter. For example<br>> > My matrix is U (m * n). I want to get i,j rows to local.<br>> > my code is<br>> ><br>> > PetscInt* rowindex,colindex;<br>> > PetscMalloc...<br>> > for (k= 0; k < n; k++)<br>> > colindex[k] = k;<br>> ><br>> > rowindex[0] = i;<br>> > rowindex[1] = j;<br>> ><br>> > MatGetSubMatrixRaw(U,1,&i,n,indices,n,MAT_INITIAL_MATRIX,&newmat);<br>> ><br>> > What I hope is newmat is 2 * n matrix. But I failed.<br>> ><br>> > Thank you<br>> ><br>> ><br>> > --- 09年12月1日,周二, Barry Smith <<a rel="nofollow">bsmith@mcs.anl.gov</a>> 写道:<br>> ><br>> > 发件人: Barry Smith <<a rel="nofollow">bsmith@mcs.anl.gov</a>><br>> > 主题:
Re: How to copy global data to local ?<br>> > 收件人: "PETSc users list" <<a rel="nofollow">petsc-users@mcs.anl.gov</a>><br>> > 日期: 2009年12月1日,周二,下午10:35<br>> ><br>> ><br>> > You misunderstand the usage of MatGetSubMatrix(). Any process can request ANY row, including rows that are not originally owned by that process.<br>> ><br>> > Barry<br>> ><br>> > On Dec 1, 2009, at 8:29 AM, ming zhu wrote:<br>> ><br>> > > 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<br>> > ><br>> >
> --- 09年12月1日,周二, Barry Smith <<a rel="nofollow">bsmith@mcs.anl.gov</a>> 写道:<br>> > ><br>> > > 发件人: Barry Smith <<a rel="nofollow">bsmith@mcs..anl.gov</a>><br>> > > 主题: Re: How to copy global data to local ?<br>> > > 收件人: "PETSc users list" <<a rel="nofollow">petsc-users@mcs.anl.gov</a>><br>> > > 日期: 2009年12月1日,周二,下午10:23<br>> > ><br>> > ><br>> > > On Nov 30, 2009, at 11:21 PM, ming zhu wrote:<br>> > ><br>> > > > Hi<br>> > > > 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 ?<br>> > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>> > ><br>> > > I do not understand what this means. To do the multiply
you can and should use a vector of PETSC_COMM_WORLD.<br>> > ><br>> > > 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().<br>> > ><br>> > > Barry<br>> > ><br>> > > > Thank you<br>> > > ><br>> > > > My original code is<br>> > > ><br>> > > > Vec filter<br>> > > > VecCreate(PETSC_COMM_WORLD,&filter);<br>> > > > VecSetsizes(filter,PETSC_DECIDE,m);<br>> > > > VecSetFromOptions(filter);<br>> > > ><br>> > > > Vecset(filter,0);<br>> > > > VecSetValue(filter,i,1,INSERT_VALUES);<br>> > > ><br>> > > > ...<br>> > > > MatMult(U, filter,ui);<br>>
> > ><br>> > > > If I create filter with PETSC_COMM_SELF, it is impossible for U and filter to multiply.<br>> > > ><br>> > > ><br>> > > ><br>> > > ><br>> > > ><br>> > > > 好玩贺卡等你发,邮箱贺卡全新上线!<br>> > ><br>> > ><br>> > > 好玩贺卡等你发,邮箱贺卡全新上线!<br>> ><br>> ><br>> > 好玩贺卡等你发,邮箱贺卡全新上线!<br>> <br>> <br>> 好玩贺卡等你发,邮箱贺卡全新上线!<br><br></div></blockquote></td></tr></tbody></table><br>
<hr size="1"><a rel="nofollow" target="_blank" href="http://cn.rd.yahoo.com/mail_cn/tagline/card/*http://card.mail.cn.yahoo.com/"> 好玩贺卡等你发,邮箱贺卡全新上线!</a></div></blockquote></td></tr></table><br>
<hr size=1><a href="http://cn.rd.yahoo.com/mail_cn/tagline/card/*http://card.mail.cn.yahoo.com/"> 好玩贺卡等你发,邮箱贺卡全新上线!</a>