<div dir="ltr">Thank you very much for your help and suggestions.<div>With your help, finally I could continue my project.</div><div><br></div><div>Regards</div><div><br></div><div>Cong Li</div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 5, 2015 at 3:09 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"><br>
From the manual page: Unless scall is MAT_REUSE_MATRIX C will be created.<br>
<br>
Since you want to use the C that is passed in you should use MAT_REUSE_MATRIX.<br>
<br>
Note that since your B and C matrices are dense the issue of sparsity pattern of C is not relevant.<br>
<span><font color="#888888"><br>
Barry<br>
</font></span><div><div><br>
> On Aug 4, 2015, at 11:59 AM, Cong Li <<a href="mailto:solvercorleone@gmail.com" target="_blank">solvercorleone@gmail.com</a>> wrote:<br>
><br>
> Thanks very much. This answer is very helpful.<br>
> And I have a following question.<br>
> If I create B1, B2, .. by the way you suggested and then use MatMatMult to do SPMM.<br>
> PetscErrorCode MatMatMult(Mat A,Mat B,MatReuse scall,PetscReal fill,Mat *C)<br>
> should I use MAT_REUSE_MATRIX for MatReuse part of the arguement.<br>
><br>
> Thanks<br>
><br>
> Cong Li<br>
><br>
> On Wed, Aug 5, 2015 at 1:27 AM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> > On Aug 4, 2015, at 4:09 AM, Cong Li <<a href="mailto:solvercorleone@gmail.com" target="_blank">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>
> 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>
><br>
> Barry<br>
><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" target="_blank">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" target="_blank">jed@jedbrown.org</a>> wrote:<br>
> > ><br>
> > > > Cong Li <<a href="mailto:solvercorleone@gmail.com" target="_blank">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>
><br>
<br>
</div></div></blockquote></div><br></div></div>