<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size: 10pt; color: rgb(0, 0, 0); font-family: Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Matthew Knepley <knepley@gmail.com><br>
<b>Sent:</b> Tuesday, April 17, 2018 8:38 AM<br>
<b>To:</b> Young, Matthew, Adam<br>
<b>Cc:</b> petsc-users@mcs.anl.gov<br>
<b>Subject:</b> Re: [petsc-users] Reuse KSP</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div class="x_gmail_extra">
<div class="x_gmail_quote">On Tue, Apr 17, 2018 at 8:33 AM, Young, Matthew, Adam <span dir="ltr">
<<a href="mailto:may@bu.edu" target="_blank" id="LPlnk383823" previewremoved="true">may@bu.edu</a>></span> wrote:<br>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div id="x_m_4622172639980718864divtagdefaultwrapper" dir="ltr" style="font-size: 10pt; color: rgb(0, 0, 0); font-family: Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<p style="margin-top:0; margin-bottom:0">My code (C/C++) uses PETSc to solve a linear system at each iteration in a time-stepping scheme. The PETSc routines are separated out because the scheme that uses them is optional in the larger code. </p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">At each time step, the PETSc scheme calls a routine that includes:</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">{</p>
<p style="margin-top:0; margin-bottom:0"> Mat A;</p>
<p style="margin-top:0; margin-bottom:0"> Vec x,b;</p>
<p style="margin-top:0; margin-bottom:0"> KSP ksp;</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> [Set up A,x,b]</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> KSPCreate(PETSC_COMM_WORLD,&<wbr>ksp);</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> [Build A and b from simulation data]</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> [Set nullspace of A with MatSetNullSpace]</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> KSPSetOperators(ksp,A,A);</p>
<p style="margin-top:0; margin-bottom:0"> KSPSetFromOptions(ksp);</p>
<p style="margin-top:0; margin-bottom:0"> KSPSolve(ksp,b,x);</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> [Write x into an instance of our array class, perform checks, etc.]</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> KSPDestroy(&ksp);</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> return(0);</p>
<p style="margin-top:0; margin-bottom:0">}</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">My question is: If I want to use superLU_DIST with the option -mat_superlu_dist_fact SamePattern (or SamePattern_SameRowPerm), should I move KSPCreate/Destroy outside of the time-step loop in the larger code?</p>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>1) Yes</div>
<div><br>
</div>
<div>2) How are you using LU when A has a nullspace?</div>
<div><span style="font-size: 10pt;">My bad - that code is in there from when I was trying iterative solvers. Should I remove it if I use LU or will PETSc just ignore it?</span><br>
</div>
<div><br>
</div>
<div>3) You can also move out SetFromOptions().</div>
<div><span style="font-size: 10pt;">Thanks for the advice. So, that means I'll build A and b from simulation data, SetOperators(), Solve(), and carry on?</span><br>
</div>
<div><br>
</div>
<div> Matt</div>
<div> </div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div id="x_m_4622172639980718864divtagdefaultwrapper" dir="ltr" style="font-size: 10pt; color: rgb(0, 0, 0); font-family: Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<p style="margin-top:0; margin-bottom:0">Thanks.</p>
<div id="x_m_4622172639980718864Signature">
<div id="x_m_4622172639980718864divtagdefaultwrapper" dir="ltr" style="font-size:10pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">----------------------------
<div>Matthew Young</div>
<div>PhD Candidate</div>
<div>Astronomy Department</div>
<div>Boston University</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div class="x_gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>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><br>
</div>
<div><a href="http://www.caam.rice.edu/~mk51/" target="_blank" id="LPlnk86175" previewremoved="true">https://www.cse.buffalo.edu/~knepley/</a><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>