<div dir="ltr">Hong,<div><br></div><div>Thanks for your answer.</div><div>However, in my problem, I have a pre-allocated matrix K, and its columns are associated with Km(1), .. Km(step_k) respectively. What I want to do is to update Km(2) by using the result of A*Km(1), and then to update Km(3) by using the product of A and updated Km(2) and so on. </div><div><br></div><div>So, I think I need to use <font color="#000000" face="Times" size="3">MAT_REUSE_MATRIX from the beginning, since even when it is the first time I call</font></div><div><span style="font-family:'Helvetica Neue';font-size:14px">MatMatMult(A,Km(stepIdx-</span><span style="font-family:'Helvetica Neue';font-size:14px">1),</span><span style="color:rgb(0,0,0);font-family:Times;font-size:medium"> </span><span style="color:rgb(0,0,0);font-family:Times;font-size:medium">MAT_REUSE_MATRIX</span><span style="font-family:'Helvetica Neue';font-size:14px">,PETSC_</span><span style="font-family:'Helvetica Neue';font-size:14px">DEFAULT_INTEGER,Km(stepIdx), </span><span style="font-family:'Helvetica Neue';font-size:14px">ierr)',</span><font color="#000000" face="Times" size="3"><br></font></div><div><span style="font-family:'Helvetica Neue';font-size:14px"><br></span></div><div><font face="Helvetica Neue"><span style="font-size:14px">Km(stepIdx) have actually already been allocated (in K).</span></font><br></div><div><font face="Helvetica Neue"><span style="font-size:14px"><br></span></font></div><div><font face="Helvetica Neue"><span style="font-size:14px">Do you think it is possible that I can do this, and could you please suggest some possible ways.</span></font></div><div><font face="Helvetica Neue"><span style="font-size:14px"><br></span></font></div><div><font face="Helvetica Neue"><span style="font-size:14px">Thanks</span></font></div><div><font face="Helvetica Neue"><span style="font-size:14px"><br></span></font></div><div><font face="Helvetica Neue"><span style="font-size:14px">Cong Li</span></font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 5, 2015 at 11:23 PM, Hong <span dir="ltr"><<a href="mailto:hzhang@mcs.anl.gov" target="_blank">hzhang@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"><div dir="ltr"><span class=""><div class="gmail_quote" style="font-size:12.8000001907349px">Cong:</div><div class="gmail_quote" style="font-size:12.8000001907349px">You cannot use "<span style="font-family:'Helvetica Neue';font-size:14px">MAT_REUSE_MATRIX" on arbitrary matrix product.</span></div><div class="gmail_quote" style="font-size:12.8000001907349px"><font face="Helvetica Neue"><span style="font-size:14px">The correct process is</span></font></div><div class="gmail_quote" style="font-size:12.8000001907349px"><font face="Helvetica Neue"><span style="font-size:14px"><br></span></font></div><div class="gmail_quote" style="font-size:12.8000001907349px"><font face="Helvetica Neue"><span style="font-size:14px">call </span></font><span style="font-family:'Helvetica Neue';font-size:14px">MatMatMult(A,Km(stepIdx-</span><span style="font-family:'Helvetica Neue';font-size:14px">1),</span><span style="color:rgb(0,0,0);font-family:Times;font-size:medium"> MAT_INITIAL_MATRIX</span><span style="font-family:'Helvetica Neue';font-size:14px">,PETSC_</span><span style="font-family:'Helvetica Neue';font-size:14px">DEFAULT_INTEGER,C, </span><span style="font-family:'Helvetica Neue';font-size:14px">ierr)</span><br></div></span><div class="gmail_quote" style="font-size:12.8000001907349px"><span style="font-family:'Helvetica Neue';font-size:14px">call MatMatMult(A,Km(stepIdx-</span><span style="font-family:'Helvetica Neue';font-size:14px">1),</span><span style="color:rgb(0,0,0);font-family:Times;font-size:medium"> MAT_REUSE_MATRIX</span><span style="font-family:'Helvetica Neue';font-size:14px">,PETSC_</span><span style="font-family:'Helvetica Neue';font-size:14px">DEFAULT_INTEGER,C, </span><span style="font-family:'Helvetica Neue';font-size:14px">ierr)</span></div><span class=""><div class="gmail_quote" style="font-size:12.8000001907349px">i.e., C has data structure of A*<span style="font-family:'Helvetica Neue';font-size:14px">Km(stepIdx-</span><span style="font-family:'Helvetica Neue';font-size:14px">1) and is created in the first call. C can be reused in the 2nd call when A or </span><span style="font-family:'Helvetica Neue';font-size:14px">Km(stepIdx-</span><span style="font-family:'Helvetica Neue';font-size:14px">1) changed values, but not the structures.</span></div><div class="gmail_quote" style="font-size:12.8000001907349px"><span style="font-family:'Helvetica Neue';font-size:14px"><br></span></div><div class="gmail_quote" style="font-size:12.8000001907349px"><span style="font-family:'Helvetica Neue';font-size:14px">In your case, </span><span style="font-family:'Helvetica Neue';font-size:14px">Km(stepIdx) = A*</span><span style="font-family:'Helvetica Neue';font-size:14px">Km(stepIdx-</span><span style="font-family:'Helvetica Neue';font-size:14px">1). You should do </span></div><div class="gmail_quote" style="font-size:12.8000001907349px"><div style="font-family:'Helvetica Neue';font-size:14px">'call MatMatMult(A,Km(stepIdx-1),<span style="color:rgb(0,0,0);font-family:Times;font-size:medium"> MAT_INITIAL_MATRIX</span>,PETSC_DEFAULT_INTEGER,Km(stepIdx), ierr)'</div><div style="font-family:'Helvetica Neue';font-size:14px">directly.</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">Hong</div></div></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 5, 2015 at 4:42 AM, Cong Li <span dir="ltr"><<a href="mailto:solvercorleone@gmail.com" target="_blank">solvercorleone@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi<div><br></div><div>I tried the method you suggested. However, I got the error message.</div><div>My code and message are below.</div><div><br></div><div><div style="font-family:'Helvetica Neue';font-size:14px">K is the big matrix containing column matrices.</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">code: </div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">call MatGetArray(K,KArray,KArrayOffset,ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">call MatGetLocalSize(R,local_RRow,local_RCol)</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">call MatGetArray(R,RArray,RArrayOffset,ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">call MatCreateDense(PETSC_COMM_WORLD, PETSC_DECIDE, &</div><div style="font-family:'Helvetica Neue';font-size:14px"> PETSC_DECIDE , nDim, bsize,KArray(KArrayOffset + 1), Km(1), ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"> localRsize = local_RRow * local_RCol</div><div style="font-family:'Helvetica Neue';font-size:14px"> do genIdx= 1, localRsize</div><div style="font-family:'Helvetica Neue';font-size:14px"> KArray(KArrayOffset + genIdx) = RArray(RArrayOffset + genIdx)</div><div style="font-family:'Helvetica Neue';font-size:14px"> end do</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"> call MatRestoreArray(R,RArray,RArrayOffset,ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"> call MatAssemblyBegin(Km(1), MAT_FINAL_ASSEMBLY, ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"> call MatAssemblyEnd (Km(1), MAT_FINAL_ASSEMBLY, ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"> do stepIdx= 2, step_k</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"> blockShift = KArrayOffset + (stepIdx-1) * (local_RRow * local_RCol)</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"> call MatCreateDense(PETSC_COMM_WORLD, PETSC_DECIDE, &</div><div style="font-family:'Helvetica Neue';font-size:14px"> PETSC_DECIDE , nDim, bsize,KArray(blockShift+1), Km(stepIdx), ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"> call MatAssemblyBegin(Km(stepIdx), MAT_FINAL_ASSEMBLY, ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"> call MatAssemblyEnd (Km(stepIdx), MAT_FINAL_ASSEMBLY, ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"> end do</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"> call MatRestoreArray(K,KArray,KArrayOffset,ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"> do stepIdx= 2, step_k</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"> call MatMatMult(A,Km(stepIdx-1),MAT_REUSE_MATRIX,PETSC_DEFAULT_INTEGER,Km(stepIdx), ierr)</div><div style="font-family:'Helvetica Neue';font-size:14px"> end do</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">And I got the error message as below:</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">
<span style="font-size:13px"><span style="font-family:Menlo">[0]PETSC ERROR: ------------------------------------------------------------------------<br>
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range<br>
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger<br>
[0]PETSC ERROR: or see <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind%5B0%5DPETSC" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind[0]PETSC</a> ERROR: or try <a href="http://valgrind.org/" target="_blank">http://valgrind.org</a> on GNU/linux and Apple Mac OS X to find memory corruption errors<br>
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run <br>
[0]PETSC ERROR: to get more information on the crash.<br>
[0]PETSC ERROR: --------------------- Error Message ------------------------------------<br>
[0]PETSC ERROR: Signal received!<br>
[0]PETSC ERROR: ------------------------------------------------------------------------<br>
[0]PETSC ERROR: Petsc Release Version 3.3.0, Patch 7, Sat May 11 22:15:24 CDT 2013 <br>
[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
[0]PETSC ERROR: See docs/index.html for manual pages.<br>
[0]PETSC ERROR: --------------------[1]PETSC ERROR: ------------------------------------------------------------------------<br>
[1]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range<br>
----------------------------------------------------<br>
[0]PETSC ERROR: ./kmath.bcbcg on a arch-fuji named p01-024 by a03293 Wed Aug 5 18:24:40 2015<br>
[0]PETSC ERROR: Libraries linked from /volume1/home/ra000005/a03293/kmathlibbuild/petsc-3.3-p7/arch-fujitsu-sparc64fx-opt/lib<br>
[0]PETSC ERROR: Configure run at Tue Jul 28 19:23:51 2015<br>
[0]PETSC ERROR: Configure options --known-level1-dcache-size=32768 --known-level1-dcache-linesize=32 --known-level1-dcache-assoc=0 --known-memcmp-ok=1 --known-sizeof-char=1 --known-sizeof-void-p=8 --known-sizeof-short=2 --known-sizeof-int=4 --known-sizeof-long=8 --known-sizeof-long-long=8 --known-sizeof-float=4 --known-sizeof-double=8 --known-sizeof-size_t=8 --known-bits-per-byte=8 --known-sizeof-MPI_Comm=8 --known-sizeof-MPI_Fint=4 --known-mpi-long-double=1 --known-mpi-c-double-complex=1 --with-cc=mpifccpx --CFLAGS="-mt -Xg" --COPTFLAGS=-Kfast,openmp --with-cxx=mpiFCCpx --CXXFLAGS=-mt --CXXOPTFLAGS=-Kfast,openmp --with-fc=mpifrtpx --FFLAGS=-Kthreadsafe --FOPTFLAGS=-Kfast,openmp --with-blas-lapack-lib="-SCALAPACK -SSL2" --with-x=0 --with-c++-support --with-batch=1 --with-info=1 --with-debugging=0 --known-mpi-shared-libraries=0 --with-valgrind=0<br>
[0]PETSC ERROR: ------------------------------------------------------------------------<br>
[0]PETSC ERROR: User provided function() line 0 in unknown directory unknown file<br>
--------------------------------------------------------------------------<br>
[mpi::mpi-api::mpi-abort]<br>
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD <br>
with errorcode 59.<br>
<br>
NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.<br>
You may or may not see output from other processes, depending on<br>
exactly when Open MPI kills them.<br>
--------------------------------------------------------------------------<br>
[p01-024:26516] /opt/FJSVtclang/GM-1.2.0-18/lib64/libmpi.so.0(orte_errmgr_base_error_abort+0x84) [0xffffffff0091f684]<br>
[p01-024:26516] /opt/FJSVtclang/GM-1.2.0-18/lib64/libmpi.so.0(ompi_mpi_abort+0x51c) [0xffffffff006c389c]<br>
[p01-024:26516] /opt/FJSVtclang/GM-1.2.0-18/lib64/libmpi.so.0(MPI_Abort+0x6c) [0xffffffff006db3ac]<br>
[p01-024:26516] /opt/FJSVtclang/GM-1.2.0-18/lib64/libtrtmet_c.so.1(MPI_Abort+0x2c) [0xffffffff00281bf0]<br>
[p01-024:26516] ./kmath.bcbcg [0x1bf620]<br>
[p01-024:26516] ./kmath.bcbcg [0x1bf20c]<br>
[p01-024:26516] /lib64/libc.so.6(killpg+0x48) [0xffffffff02d52600]<br>
[p01-024:26516] [(nil)]<br>
[p01-024:26516] ./kmath.bcbcg [0x1a2054]<br>
[p01-024:26516] ./kmath.bcbcg [0x1064f8]<br>
[p01-024:26516] ./kmath.bcbcg(MAIN__+0x9dc) [0x105d1c]<br>
[p01-024:26516] ./kmath.bcbcg(main+0xec) [0x8a329c]<br>
[p01-024:26516] /lib64/libc.so.6(__libc_start_main+0x194) [0xffffffff02d3b81c]<br>
[p01-024:26516] ./kmath.bcbcg [0x1051ec]<br>
[0]PETSC ERROR: ------------------------------------------------------------------------<br>
[0]PETSC ERROR: Caught signal number 15 Terminate: Somet process (or the batch system) has told this process to end<br>
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger<br>
[0]PETSC ERROR: or see <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind%5B0%5DPETSC" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind[0]PETSC</a> ERROR: or try <a href="http://valgrind.org/" target="_blank">http://valgrind.org</a> on GNU/linux and Apple Mac OS X to find memory corruption errors<br>
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run <br>
[0]PETSC ERROR: to get more information on the crash.<br>
[0]PETSC ERROR: --------------------- Error Message ------------------------------------<br>
[0]PETSC ERROR: Signal received!<br>
[0]PETSC ERROR: ------------------------------------------------------------------------<br>
[0]PETSC ERROR: Petsc Release Version 3.3.0, Patch 7, Sat May 11 22:15:24 CDT 2013 <br>
[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
[0]PETSC ERROR: See docs/index.html for manual pages.<br>
[0]PETSC ERROR: ------------------------------------------------------------------------<br>
[0]PETSC ERROR: ./kmath.bcbcg on a arch-fuji named p01-024 by a03293 Wed Aug 5 18:24:40 2015<br>
[0]PETSC ERROR: Libraries linked from /volume1/home/ra000005/a03293/kmathlibbuild/petsc-3.3-p7/arch-fujitsu-sparc64fx-opt/lib<br>
[0]PETSC ERROR: Configure run at Tue Jul 28 19:23:51 2015<br>
[0]PETSC ERROR: Configure options --known-level1-dcache-size=32768 --known-level1-dcache-linesize=32 --known-level1-dcache-assoc=0 --known-memcmp-ok=1 --known-sizeof-char=1 --known-sizeof-void-p=8 --known-sizeof-short=2 --known-sizeof-int=4 --known-sizeof-long=8 --known-sizeof-long-long=8 --known-sizeof-float=4 --known-sizeof-double=8 --known-sizeof-size_t=8 --known-bits-per-byte=8 --known-sizeof-MPI_Comm=8 --known-sizeof-MPI_Fint=4 --known-mpi-long-double=1 --known-mpi-c-double-complex=1 --with-cc=mpifccpx --CFLAGS="-mt -Xg" --COPTFLAGS=-Kfast,openmp --with-cxx=mpiFCCpx --CXXFLAGS=-mt --CXXOPTFLAGS=-Kfast,openmp --with-fc=mpifrtpx --FFLAGS=-Kthreadsafe --FOPTFLAGS=-Kfast,openmp --with-blas-lapack-lib="-SCALAPACK -SSL2" --with-x=0 --with-c++-support --with-batch=1 --with-info=1 --with-debugging=0 --known-mpi-shared-libraries=0 --with-valgrind=0<br>
[0]PETSC ERROR: ------------------------------------------------------------------------<br>
[0]PETSC ERROR: User provided function() line 0 in unknown directory unknown file</span></span></div><div style="font-family:'Helvetica Neue';font-size:14px"><span style="font-size:13px"><span style="font-family:Menlo">
[ERR.] PLE 0019 plexec One of MPI processes was aborted.(rank=0)(nid=0x020a0028)(CODE=1938,793745140674134016,15104)</span></span></div></div><div style="font-family:'Helvetica Neue';font-size:14px"><span style="font-size:13px"><span style="font-family:Menlo"><br></span></span></div><div style="font-family:'Helvetica Neue';font-size:14px"><span style="font-size:13px"><span style="font-family:Menlo">However, if I change from </span></span></div><div style="font-family:'Helvetica Neue';font-size:14px">call MatMatMult(A,Km(stepIdx-1),MAT_REUSE_MATRIX,PETSC_DEFAULT_INTEGER,Km(stepIdx), ierr)<span style="font-size:13px"><span style="font-family:Menlo"><br></span></span></div><div style="font-family:'Helvetica Neue';font-size:14px">to </div><div style="font-family:'Helvetica Neue';font-size:14px">call MatMatMult(A,Km(stepIdx-1),<span style="color:rgb(0,0,0);font-family:Times;font-size:medium"> MAT_INITIAL_MATRIX</span>,PETSC_DEFAULT_INTEGER,Km(stepIdx), ierr)<br></div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">everything is fine.</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">could you please suggest some way to solve this?</div><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">Thanks</div><span><font color="#888888"><div style="font-family:'Helvetica Neue';font-size:14px"><br></div><div style="font-family:'Helvetica Neue';font-size:14px">Cong Li</div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 5, 2015 at 10:53 AM, Cong Li <span dir="ltr"><<a href="mailto:solvercorleone@gmail.com" target="_blank">solvercorleone@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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><span><font color="#888888"><div><br></div><div>Cong Li</div></font></span><div><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></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>