<div dir="ltr">Thanks Hong.<br><br><div class="gmail_quote">On Tue, Apr 24, 2012 at 4:25 PM, Hong Zhang <span dir="ltr">&lt;<a href="mailto:hzhang@mcs.anl.gov" target="_blank">hzhang@mcs.anl.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="gmail_extra"><span style="font-family:Times;font-size:medium">See </span></div><div class="gmail_extra"><span style="font-family:Times;font-size:medium"><a href="http://www.mcs.anl.gov/petsc/documentation/changes/dev.html" target="_blank">http://www.mcs.anl.gov/petsc/documentation/changes/dev.html</a>:</span></div>


<div class="gmail_extra"><span style="font-family:Times;font-size:medium"><br></span></div><div class="gmail_extra"><span style="font-family:Times;font-size:medium">You MUST now call MatXXXSetPreallocation() or MatSetUp() on any matrix you create directly (not using DMCreateMatrix()) before calling MatSetValues(), MatSetValuesBlocked() etc.</span></div>


<div class="gmail_extra"><font face="Times" size="3"><br></font><br><div class="gmail_quote"><div class="im">On Tue, Apr 24, 2012 at 6:01 PM, Mohammad Mirzadeh <span dir="ltr">&lt;<a href="mailto:mirzadeh@gmail.com" target="_blank">mirzadeh@gmail.com</a>&gt;</span> wrote:<br>


</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="im">Hi,<div><br></div><div>While trying to figure out a problem, I came across the following situation. Consider the following code:</div>


<div><br></div><div>
<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#808bed">int</span><span style="color:#646482"> </span>main<span style="color:#646482"> </span><span style="color:#409040">(</span><span style="color:#808bed">int</span><span style="color:#646482"> </span>argc<span style="color:#409040">,</span><span style="color:#646482"> </span><span style="color:#808bed">char</span><span style="color:#646482"> </span><span style="color:#409040">**</span>argv<span style="color:#409040">){</span></font></pre>





<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span>PetscInitialize<span style="color:#409040">(&amp;</span>argc<span style="color:#409040">,</span><span style="color:#646482"> </span><span style="color:#409040">&amp;</span>argv<span style="color:#409040">,</span><span style="color:#646482"> </span><span style="color:#409040">(</span><span style="color:#808bed">char</span><span style="color:#409040">*)</span><span style="color:#506bbd">0</span><span style="color:#409040">,</span><span style="color:#646482"> </span>help<span style="color:#409040">);</span></font></pre>





<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span><span style="color:#ff8bff">Mat</span><span style="color:#646482"> </span>m<span style="color:#409040">;</span></font></pre>





<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span>MatCreate<span style="color:#409040">(</span>PETSC_COMM_WORLD<span style="color:#409040">,</span><span style="color:#646482"> </span><span style="color:#409040">&amp;</span>m<span style="color:#409040">);</span></font></pre>





<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span>MatSetSizes<span style="color:#409040">(</span>m<span style="color:#409040">,</span><span style="color:#646482"> </span><span style="color:#506bbd">10</span><span style="color:#409040">,</span><span style="color:#646482"> </span><span style="color:#506bbd">10</span><span style="color:#409040">,</span><span style="color:#646482"> </span>PETSC_DECIDE<span style="color:#409040">,</span><span style="color:#646482"> </span>PETSC_DECIDE<span style="color:#409040">);</span></font></pre>





<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span>MatSetFromOptions<span style="color:#409040">(</span>m<span style="color:#409040">);</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span>MatAssemblyBegin<span style="color:#409040">(</span>m<span style="color:#409040">,</span><span style="color:#646482"> </span><span style="color:#cb6ecb">MAT_FINAL_ASSEMBLY</span><span style="color:#409040">);</span></font></pre>





<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span>MatAssemblyEnd<span style="color:#409040">(</span>m<span style="color:#409040">,</span><span style="color:#646482"> </span><span style="color:#cb6ecb">MAT_FINAL_ASSEMBLY</span><span style="color:#409040">);</span></font></pre>





<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span>MatView<span style="color:#409040">(</span>m<span style="color:#409040">,</span><span style="color:#646482"> </span>PETSC_VIEWER_STDOUT_WORLD<span style="color:#409040">);</span></font></pre>





<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span>MatDestroy<span style="color:#409040">(&amp;</span>m<span style="color:#409040">);</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span>PetscFinalize<span style="color:#409040">();</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font size="4"><span style="color:#646482">    </span><span style="color:#808bed">return</span><span style="color:#646482"> </span><span style="color:#506bbd">0</span><span style="color:#409040">;</span></font></pre>





<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#409040"><font size="4">}</font></span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:#409040"><br></span></pre>This runs without any problem under 3.2-p6 but fails with petsc-dev:</div>




<div><br></div><div><div>[0]PETSC ERROR: --------------------- Error Message ------------------------------------</div><div>[0]PETSC ERROR: Object is in wrong state!</div><div>[0]PETSC ERROR: Must call MatXXXSetPreallocation() or MatSetUp() on argument 1 &quot;mat&quot; before MatAssemblyBegin()!</div>




<div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div><br></div></div></div><div class="im"><div>Eventually I could fix this by adding MatSetUp(m) after setting the options. Why do I need this in petsc-dev? Does this somehow preallocate the matrix?</div>


</div></div></blockquote><div>Yes.</div><div><br></div><div>Hong </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">

<div><br></div><div>Thanks,</div><div>Mohammad</div></div>
</blockquote></div><br></div>
</blockquote></div><br></div>