<div dir="ltr">Barry, Matt,<div><br></div><div>Thank you both.</div><div><br></div><div>Mohammad<br><br><div class="gmail_quote">On Mon, Apr 30, 2012 at 6:05 PM, Barry Smith <span dir="ltr">&lt;<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@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="im"><br>
On Apr 30, 2012, at 6:57 PM, Matthew Knepley wrote:<br>
<br>
&gt; On Mon, Apr 30, 2012 at 7:01 PM, Mohammad Mirzadeh &lt;<a href="mailto:mirzadeh@gmail.com">mirzadeh@gmail.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; Just a quick question. Following petsc-dev/src/ksp/ksp/examples/tutorials/ex2.c, it seems that I need to call both MatMPIAIJSetPreallocation and MatSeqAIJSetPreallocation to be able to preallocate for both MPI and Seq matrices. Does petsc automatically chose the relevant function when the code is run in serial and parallel?<br>


<br>
</div>    Yes, it uses the relevant one and ignores any not relevant.<br>
<br>
    This is a common trick in PETSc. You can think of the calls as methods specific to a particular subclass of the Mat class. PETSc automatically uses all the methods that are appropriate for the particular subclass and ignores all the other ones.<br>


<span class="HOEnZb"><font color="#888888"><br>
    Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
&gt; In other words, what is the effect of MatMPIAIJSetPreallocation(MatSeqAIJSetPreallocation) when the code is run in serial(parallel)?<br>
&gt;<br>
&gt; I like how several functions are abstract and can be used both in serial and parallel (like MatCreate). Is there a similar way to just call a single &quot;MatSetPreallocation&quot; function?<br>
&gt;<br>
&gt; <a href="http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Mat/MatXAIJSetPreallocation.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Mat/MatXAIJSetPreallocation.html</a><br>
&gt;<br>
&gt;    Matt<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Mohammad<br>
&gt;<br>
&gt; On Wed, Apr 25, 2012 at 4:04 PM, Mohammad Mirzadeh &lt;<a href="mailto:mirzadeh@gmail.com">mirzadeh@gmail.com</a>&gt; wrote:<br>
&gt; Thanks Hong; that fixed the problem.<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Apr 25, 2012 at 11:31 AM, Hong Zhang &lt;<a href="mailto:hzhang@mcs.anl.gov">hzhang@mcs.anl.gov</a>&gt; wrote:<br>
&gt; Mohammad:<br>
&gt;<br>
&gt; MatCreate(comm, &amp;A);<br>
&gt; MatSetSizes(A, localRowSize, localColumnSize, globalRowSize, globalColumnSize);<br>
&gt; MatSetType(A, MATMPIAIJ);<br>
&gt; MatMPIAIJSetPreallocation(A, 0, d_nnz, 0, o_nnz);<br>
&gt; MatSetFromOptions(A);<br>
&gt; MatGetOwnershipRange(A, &amp;rStart, &amp;rEnd);<br>
&gt;<br>
&gt;<br>
&gt; This (even without MatSetType(A, MATMPIAIJ);) works with 3.2-p6 but not dev. The only difference I can see is 1) the order of MatSetFromOptions and 2) I do not call MatSeqAIJSetPreallocation which I think I do not need anyway. Is there something I&#39;m doing wrong?<br>


&gt;<br>
&gt; MatSetFromOptions() must be called before MatMPIAIJSetPreallocation().<br>
&gt; If user set mattype at runtime, MatSetFromOptions() picks it and set the type accordingly. SetPreallocation()<br>
&gt; will be called after the type is set.<br>
&gt;<br>
&gt; Hong<br>
&gt;<br>
&gt; Mohammd<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
&gt; -- Norbert Wiener<br>
<br>
</div></div></blockquote></div><br></div></div>