<div dir="ltr">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>[0]PETSC ERROR: Petsc Development HG revision: 5c943f0d8cbf252873fd4abeffa38c8d3c15987e  HG Date: Mon Apr 09 22:04:11 2012 -0500</div>

<div>[0]PETSC ERROR: See docs/changes/index.html for recent updates.</div><div>[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.</div><div>[0]PETSC ERROR: See docs/index.html for manual pages.</div><div>

[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: ./petsc on a arch-linu named mohammad-laptop by mohammad Tue Apr 24 15:55:40 2012</div><div>[0]PETSC ERROR: Libraries linked from /home/mohammad/soft/petsc-dev/arch-linux2-cxx-debug/lib</div>

<div>[0]PETSC ERROR: Configure run at Mon Apr  9 23:17:27 2012</div><div>[0]PETSC ERROR: Configure options --with-clanguage=cxx --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich=1 --download-f-blas-lapack=1 --download-hypre=1 --download-superlu_dist=1 --download-metis=1 --download-parmetis=1</div>

<div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: MatAssemblyBegin() line 4810 in /home/mohammad/soft/petsc-dev/src/mat/interface/matrix.c</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div>

<div>[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range</div><div>[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger</div><div>[0]PETSC ERROR: or see <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind[0]PETSC">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind[0]PETSC</a> ERROR: or try <a href="http://valgrind.org">http://valgrind.org</a> on GNU/linux and Apple Mac OS X to find memory corruption errors</div>

<div>[0]PETSC ERROR: likely location of problem given in stack below</div><div>[0]PETSC ERROR: ---------------------  Stack Frames ------------------------------------</div><div>[0]PETSC ERROR: Note: The EXACT line numbers in the stack are not available,</div>

<div>[0]PETSC ERROR:       INSTEAD the line number of the start of the function</div><div>[0]PETSC ERROR:       is given.</div><div>[0]PETSC ERROR: [0] MatAssemblyEnd_SeqAIJ line 800 /home/mohammad/soft/petsc-dev/src/mat/impls/aij/seq/aij.c</div>

<div>[0]PETSC ERROR: [0] MatAssemblyEnd line 4984 /home/mohammad/soft/petsc-dev/src/mat/interface/matrix.c</div><div>[0]PETSC ERROR: [0] MatAssemblyBegin line 4807 /home/mohammad/soft/petsc-dev/src/mat/interface/matrix.c</div>

<div>[0]PETSC ERROR: --------------------- Error Message ------------------------------------</div><div>[0]PETSC ERROR: Signal received!</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div>

<div>[0]PETSC ERROR: Petsc Development HG revision: 5c943f0d8cbf252873fd4abeffa38c8d3c15987e  HG Date: Mon Apr 09 22:04:11 2012 -0500</div><div>[0]PETSC ERROR: See docs/changes/index.html for recent updates.</div><div>[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.</div>

<div>[0]PETSC ERROR: See docs/index.html for manual pages.</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: ./petsc on a arch-linu named mohammad-laptop by mohammad Tue Apr 24 15:55:40 2012</div>

<div>[0]PETSC ERROR: Libraries linked from /home/mohammad/soft/petsc-dev/arch-linux2-cxx-debug/lib</div><div>[0]PETSC ERROR: Configure run at Mon Apr  9 23:17:27 2012</div><div>[0]PETSC ERROR: Configure options --with-clanguage=cxx --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich=1 --download-f-blas-lapack=1 --download-hypre=1 --download-superlu_dist=1 --download-metis=1 --download-parmetis=1</div>

<div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: User provided function() line 0 in unknown directory unknown file</div><div>application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0</div>

<div>[unset]: aborting job:</div><div>application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0</div></div><div><br></div><div><br></div><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><br></div><div>Thanks,</div><div>Mohammad</div></div>