<div dir="ltr">Thanks very much. This answer is very helpful.<div>And I have a following question.</div><div>If I create B1, B2, .. by the way you suggested and then use MatMatMult to do SPMM. </div><div><pre style="color:rgb(0,0,0)"><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMatMult.html#MatMatMult">MatMatMult</a>(<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/Mat.html#Mat">Mat</a> A,<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/Mat.html#Mat">Mat</a> B,<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatReuse.html#MatReuse">MatReuse</a> scall,<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</a> fill,<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/Mat.html#Mat">Mat</a> *C)</pre></div><div>should I use  MAT_REUSE_MATRIX for MatReuse part of the arguement. </div><div><br></div><div>Thanks</div><div><br></div><div>Cong Li</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 5, 2015 at 1:27 AM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Aug 4, 2015, at 4:09 AM, Cong Li <<a href="mailto:solvercorleone@gmail.com">solvercorleone@gmail.com</a>> wrote:<br>
><br>
> I am sorry that I should have explained it more clearly.<br>
> Actually I want to compute a recurrence.<br>
><br>
> Like, I want to firstly compute A*X1=B1, and then calculate A*B1=B2, A*B2=B3 and so on.<br>
> Finally I want to combine all these results into a bigger matrix C=[B1,B2 ...]<br>
<br>
</span>   First create C with MatCreateDense(,&C). Then call MatDenseGetArray(C,&array); then create B1 with MatCreateDense(....,array,&B1); then create<br>
B2 with MatCreateDense(...,array+shift,&B2) etc where shift equals the number of __local__ rows in B1 times the number of columns in B1, then create B3 with a larger shift etc.<br>
<br>
   Note that you are "sharing" the array space of C with B1, B2, B3, ..., each Bi contains its columns of the C matrix.<br>
<span class="HOEnZb"><font color="#888888"><br>
  Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
><br>
> Is there any way to do this efficiently.<br>
><br>
><br>
><br>
> On Tue, Aug 4, 2015 at 5:45 PM, Patrick Sanan <<a href="mailto:patrick.sanan@gmail.com">patrick.sanan@gmail.com</a>> wrote:<br>
> On Tue, Aug 04, 2015 at 03:42:14PM +0900, Cong Li wrote:<br>
> > Thanks for your reply.<br>
> ><br>
> > I have an other question.<br>
> > I want to do SPMM several times and combine result matrices into one bigger<br>
> > matrix.<br>
> > for example<br>
> > I firstly calculate AX1=B1, AX2=B2 ...<br>
> > then I want to combine B1, B2.. to get a C, where C=[B1,B2...]<br>
> ><br>
> > Could you please suggest a way of how to do this.<br>
> This is just linear algebra, nothing to do with PETSc specifically.<br>
> A * [X1, X2, ... ] = [AX1, AX2, ...]<br>
> ><br>
> > Thanks<br>
> ><br>
> > Cong Li<br>
> ><br>
> > On Tue, Aug 4, 2015 at 3:27 PM, Jed Brown <<a href="mailto:jed@jedbrown.org">jed@jedbrown.org</a>> wrote:<br>
> ><br>
> > > Cong Li <<a href="mailto:solvercorleone@gmail.com">solvercorleone@gmail.com</a>> writes:<br>
> > ><br>
> > > > Hello,<br>
> > > ><br>
> > > > I am a PhD student using PETsc for my research.<br>
> > > > I am wondering if there is a way to implement SPMM (Sparse matrix-matrix<br>
> > > > multiplication) by using PETSc.<br>
> > ><br>
> > ><br>
> > > <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMatMult.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMatMult.html</a><br>
> > ><br>
><br>
<br>
</div></div></blockquote></div><br></div>