<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"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></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>
> On Mon, Apr 30, 2012 at 7:01 PM, Mohammad Mirzadeh <<a href="mailto:mirzadeh@gmail.com">mirzadeh@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> 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>
> In other words, what is the effect of MatMPIAIJSetPreallocation(MatSeqAIJSetPreallocation) when the code is run in serial(parallel)?<br>
><br>
> 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 "MatSetPreallocation" function?<br>
><br>
> <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>
><br>
> Matt<br>
><br>
> Thanks,<br>
> Mohammad<br>
><br>
> On Wed, Apr 25, 2012 at 4:04 PM, Mohammad Mirzadeh <<a href="mailto:mirzadeh@gmail.com">mirzadeh@gmail.com</a>> wrote:<br>
> Thanks Hong; that fixed the problem.<br>
><br>
><br>
> On Wed, Apr 25, 2012 at 11:31 AM, Hong Zhang <<a href="mailto:hzhang@mcs.anl.gov">hzhang@mcs.anl.gov</a>> wrote:<br>
> Mohammad:<br>
><br>
> MatCreate(comm, &A);<br>
> MatSetSizes(A, localRowSize, localColumnSize, globalRowSize, globalColumnSize);<br>
> MatSetType(A, MATMPIAIJ);<br>
> MatMPIAIJSetPreallocation(A, 0, d_nnz, 0, o_nnz);<br>
> MatSetFromOptions(A);<br>
> MatGetOwnershipRange(A, &rStart, &rEnd);<br>
><br>
><br>
> 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'm doing wrong?<br>
><br>
> MatSetFromOptions() must be called before MatMPIAIJSetPreallocation().<br>
> If user set mattype at runtime, MatSetFromOptions() picks it and set the type accordingly. SetPreallocation()<br>
> will be called after the type is set.<br>
><br>
> Hong<br>
><br>
> Mohammd<br>
><br>
><br>
><br>
><br>
><br>
><br>
> --<br>
> 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<br>
<br>
</div></div></blockquote></div><br></div></div>