<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: times new roman,new york,times,serif; font-size: 12pt; color: #000000'>Hi Matt,<div><br></div><div>The motivation is to calculate density matrix in electronic structure calculations.</div><div>The density matrix can be obtained recursively iterations (known as density matrix purification). An example is</div><div><br></div><div>X_{n+1} = 3 X_n^2 - 2 <span style="font-size: 12pt;">X_n^3</span></div><div><span style="font-size: 12pt;"><br></span></div><div><span style="font-size: 12pt;">Density matrix has property of off diagonal decay. </span></div><div><span style="font-size: 12pt;"><br></span></div><div>To do this I was planning to setup the non-zero structure of these matrices using the decay estimates and then proceed with the iteration such that the non-zero structure of the product matrices are preserved. In doing so I would need to do MatMatMultSymbolic once.</div><div><br></div><div>Another option I thought of is to truncate the values in the product matrix after <span style="font-size: 12pt;">MatMatMultNumeric. However this would require to do </span><span style="font-size: 12pt;">MatMatMultSymbolic for every subsequent matrix product and also matrix assembly after every truncation and would not be very efficient.</span></div><div><span style="font-size: 12pt;"><br></span></div><div><span style="font-size: 12pt;">Please let me know if you have any other thoughts regarding this.</span></div><div><span style="font-size: 12pt;"><br></span></div><div><span style="font-size: 12pt;"><br></span></div><div><span style="font-size: 12pt;">Regards.</span></div><div><span style="font-size: 12pt;">Swarnava</span></div><div><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Matthew Knepley" <knepley@gmail.com><br><b>To: </b>"Swarnava Ghosh" <sghosh2012@gatech.edu><br><b>Cc: </b>"PETSc users list" <petsc-users@mcs.anl.gov><br><b>Sent: </b>Thursday, September 3, 2015 7:57:28 PM<br><b>Subject: </b>Re: [petsc-users] Preserving nonzero structure during MatMatMult<br><br><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 3, 2015 at 6:55 PM, Ghosh, Swarnava <span dir="ltr"><<a href="mailto:sghosh2012@gatech.edu" target="_blank">sghosh2012@gatech.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
  I want to do the following:<br>
Matrices DM1, DM2 and DM3 (MPIAIJ type) have the same non zero structure. I want to multiply DM1*DM2=DM3. BUT the resulting matrix should preserve the initial non-zero pattern that was set to it. Basically multiplication should not create new non-zero locations.<br>
<br>
For this I do:<br>
<br>
/* after setting the nonzero locations/*<br>
<br>
    ierr =  MatAssemblyBegin(DM1,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);<br>
    ierr =  MatAssemblyEnd(DM1,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);<br>
<br>
   MatSetOption(DM1,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE);<br>
   MatSetOption(DM1,MAT_KEEP_NONZERO_PATTERN,PETSC_TRUE);<br>
<br>
<br>
 Similarly for the matrices DM2 and DM3, the above is done.<br>
<br>
However When I do MatMatMultSymbolic, the number of non-zeros change,<br>
<br>
BEFORE MULT: NNZ allocated : 531441.000000 NNZ used: 518155.000000<br>
AFTER MULT: NNZ allocated : 2350209.000000 NNZ used: 2350209.000000<br>
<br>
<br>
Could you let me know how do I preserve the nonzero locations after MatMatMult?<br></blockquote><div><br></div><div>We do not support that. What is the motivation?</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Regards,<br>
Swarnava<br>
<span class="HOEnZb"><font color="#888888">--<br>
Swarnava Ghosh<br>
PhD Candidate,<br>
Structural Engineering, Mechanics and Materials<br>
School of Civil and Environmental Engineering<br>
Georgia Institute of Technology<br>
Atlanta, GA 30332<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div>
</div><br><br><br>-- <br><div><span name="x"></span>Swarnava Ghosh<br>PhD Candidate,<br>Structural Engineering, Mechanics and Materials<br>School of Civil and Environmental Engineering<br>Georgia Institute of Technology<br>Atlanta, GA 30332<span name="x"></span><br></div></div></div></body></html>