<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">OK. I am now use MatGetSubMatrix.My code is as follows<br><br>&nbsp; PetscMalloc(n*sizeof(PetscInt),&amp;indices);&nbsp; <br>&nbsp; for (j = 0; j &lt; n; j++)<br>&nbsp; {&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; indices[j] = j; <br>&nbsp; } <br>&nbsp; ISCreateGeneral(PETSC_COMM_SELF,n,indices,&amp;iy); // get all columns <br>&nbsp;.....<br><br>&nbsp;&nbsp; PetscMalloc(2*sizeof(PetscInt),&amp;indices);&nbsp; <br>&nbsp;&nbsp;&nbsp; indices[0] = i;<br>&nbsp;&nbsp;&nbsp; indices[1] = j;<br>&nbsp;&nbsp;&nbsp; ISCreateGeneral(PETSC_COMM_SELF,2,indices,&amp;ix);&nbsp;&nbsp;&nbsp;&nbsp; // only get i,j rows<br><br>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp;&nbsp; ierr = MatGetSubMatrix(U,ix,iy,n,
 MAT_INITIAL_MATRIX,&amp;ui);CHKERRQ(ierr);<br><br>What I really hope is to <br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; n; i++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscInt row = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MatGetValues(ui,1,&amp;row,1,&amp;i,&amp;u_ik);<br>}<br>It does not work. I tried to change the n to PETSC_DECIDE, it still does not work<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>&nbsp;MatCreateMPIDense(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_NULL,&amp;U)<br><br>THank you<br>--- <b>09年12月2日,周三, Barry Smith <i>&lt;bsmith@mcs.anl.gov&gt;</i></b> 写道:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>发件人: Barry Smith &lt;bsmith@mcs.anl.gov&gt;<br>主题: Re: How
 to copy global data to local ?<br>收件人: "PETSc users list" &lt;petsc-users@mcs.anl.gov&gt;<br>日期: 2009年12月2日,周三,下午1:46<br><br><div class="plainMail"><br>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;Barry<br><br>On Dec 1, 2009, at 9:59 PM, ming zhu wrote:<br><br>&gt; Hi<br>&gt; I tried MatGetSubMatrix() but I am a little confused by the column parameter. For example<br>&gt; My matrix is U (m * n). I want to get i,j rows to local.<br>&gt; my code is<br>&gt; <br>&gt; PetscInt* rowindex,colindex;<br>&gt; PetscMalloc...<br>&gt; for (k= 0; k &lt; n; k++)<br>&gt;&nbsp; &nbsp; colindex[k] = k;<br>&gt; <br>&gt; rowindex[0] =
 i;<br>&gt; rowindex[1] = j;<br>&gt; <br>&gt; MatGetSubMatrixRaw(U,1,&amp;i,n,indices,n,MAT_INITIAL_MATRIX,&amp;newmat);<br>&gt; <br>&gt; What I hope is newmat is 2 * n matrix. But I failed.<br>&gt; <br>&gt; Thank you<br>&gt; <br>&gt; <br>&gt; --- 09年12月1日,周二, Barry Smith &lt;<a ymailto="mailto:bsmith@mcs.anl.gov" href="/mc/compose?to=bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>&gt; 写道:<br>&gt; <br>&gt; 发件人: Barry Smith &lt;<a ymailto="mailto:bsmith@mcs.anl.gov" href="/mc/compose?to=bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>&gt;<br>&gt; 主题: Re: How to copy global data to local ?<br>&gt; 收件人: "PETSc users list" &lt;<a ymailto="mailto:petsc-users@mcs.anl.gov" href="/mc/compose?to=petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>&gt;<br>&gt; 日期: 2009年12月1日,周二,下午10:35<br>&gt; <br>&gt; <br>&gt;&nbsp; &nbsp; You misunderstand the usage of MatGetSubMatrix(). Any process can request ANY row, including rows
 that are not originally owned by that process.<br>&gt; <br>&gt;&nbsp; &nbsp; Barry<br>&gt; <br>&gt; On Dec 1, 2009, at 8:29 AM, ming zhu wrote:<br>&gt; <br>&gt; &gt; It seems that MatGetSubMatrix() only get the local matrix for the processor&nbsp; 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>&gt; &gt;<br>&gt; &gt; --- 09年12月1日,周二, Barry Smith &lt;<a ymailto="mailto:bsmith@mcs.anl.gov" href="/mc/compose?to=bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>&gt; 写道:<br>&gt; &gt;<br>&gt; &gt; 发件人: Barry Smith &lt;<a ymailto="mailto:bsmith@mcs.anl.gov" href="/mc/compose?to=bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>&gt;<br>&gt; &gt; 主题: Re: How to copy global data to local ?<br>&gt; &gt; 收件人: "PETSc users list" &lt;<a
 ymailto="mailto:petsc-users@mcs.anl.gov" href="/mc/compose?to=petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>&gt;<br>&gt; &gt; 日期: 2009年12月1日,周二,下午10:23<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; On Nov 30, 2009, at 11:21 PM, ming zhu wrote:<br>&gt; &gt;<br>&gt; &gt; &gt; Hi<br>&gt; &gt; &gt; 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.&nbsp; 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>&gt; &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>&gt; &gt;<br>&gt; &gt;&nbsp; &nbsp; I do not understand what this means. To do the multiply you can and should use a vector of PETSC_COMM_WORLD.<br>&gt; &gt;<br>&gt; &gt;&nbsp; &nbsp; 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>&gt; &gt;<br>&gt; &gt;&nbsp; &nbsp; Barry<br>&gt; &gt;<br>&gt; &gt; &gt; Thank you<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; My original code is<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Vec
 filter<br>&gt; &gt; &gt; VecCreate(PETSC_COMM_WORLD,&amp;filter);<br>&gt; &gt; &gt; VecSetsizes(filter,PETSC_DECIDE,m);<br>&gt; &gt; &gt; VecSetFromOptions(filter);<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Vecset(filter,0);<br>&gt; &gt; &gt; VecSetValue(filter,i,1,INSERT_VALUES);<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; ...<br>&gt; &gt; &gt; MatMult(U, filter,ui);<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; If I create filter with PETSC_COMM_SELF, it is impossible for U and filter to multiply.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; 好玩贺卡等你发,邮箱贺卡全新上线!<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; 好玩贺卡等你发,邮箱贺卡全新上线!<br>&gt; <br>&gt; <br>&gt; 好玩贺卡等你发,邮箱贺卡全新上线!<br><br></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>