<div dir="ltr">On Wed, Oct 2, 2013 at 1:32 PM, Mohammad Mirzadeh <span dir="ltr"><<a href="mailto:mirzadeh@gmail.com" target="_blank">mirzadeh@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Matt,<br>
<br>
I just discovered that my approach does not work properly with<br>
VecGhostUpdateBegin/End -- I get wrong data after ghost update<br>
process. Any idea why? When I change the IS, is PETSc aware that my<br>
ghost values are not just at the end of vector?<br></blockquote><div><br></div><div>Then I was probably misunderstanding what you want to do.</div><div><br></div><div> 1) L2GM is for translating local to global indices automatically, but knows nothing about "ghosting" in the Vec</div>
<div><br></div><div> 2) For ghosting, you have a local vector and global vector and a VecScatter that maps between them</div><div><br></div><div> 3) VecGhost is a special kind of 2) since we know that the local vector fits in side the global vec</div>
<div><br></div><div> 4) Since you break relationship 3), I would just use the DM (as I say below).</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Mohammad<br>
<br>
On Wed, Oct 2, 2013 at 4:13 AM, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>
> On Wed, Oct 2, 2013 at 12:27 AM, Mohammad Mirzadeh <<a href="mailto:mirzadeh@gmail.com">mirzadeh@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Hi guys,<br>
>><br>
>> I just did something by pure guessing which seems to work and I want<br>
>> to make sure its the right thing!<br>
>><br>
>> I have a specific layout for my vectors that look like this<br>
>><br>
>> --------------------------------------------------------------<br>
>> | ghost values | local values | ghost values |<br>
>> --------------------------------------------------------------<br>
>> 0, 1, 2, ... m, m+1, ... m+n, m+n+1 ... N<br>
>><br>
>> which means all nodes with index [0,m) and [m+n, N) are to be treated<br>
>> as ghost and all intermediate ones as local. Since PETSc stores the<br>
>> ghost values at the end of ghosted vec, so far I have been manually<br>
>> mapping back and forth between petsc and my application numbering.<br>
>> After profiling my code, it turned out that about 15% of run-time was<br>
>> just doing this mapping which is absolutely ridiculous!<br>
>><br>
>> Anyway, to fix this now I set up an ISLocalToGlobalMapping object<br>
>> using my own application original local2global relation shown above.<br>
>> Then I create the petsc vec like this:<br>
>><br>
>> // Create PetscVec<br>
>> // We do not care about the actual global index of ghost nodes at this<br>
>> point<br>
>> std::vector<PetscInt> ghost_nodes(N - n -1, 0);<br>
>> ierr = VecCreateGhost(mpicomm, n+1, num_global, ghost_nodes.size(),<br>
>> (const PetscInt*)&ghost_nodes[0], &v); CHKERRQ(ierr);<br>
>><br>
>><br>
>> // Apply mapping<br>
>> ierr = VecSetLocalToGlobalMapping(v, mapping); CHKERRQ(ierr);<br>
>><br>
>> After this point I do the usual VecGetArray on the vec and set the<br>
>> values, but this time without any extra mapping ... my very simple<br>
>> test seems to be ok. Is this the correct way of using<br>
>> ISLocalToGlobalMapping?<br>
><br>
><br>
> Yes, this is the intention. And at a higher level, PETSc now tends to use a<br>
> DM to<br>
> organize this process. You tell the DM about your data layout (somewhat like<br>
> giving<br>
> the L2G mapping) and then you can DMGetLocalVector(), DMGetGlobalVector(),<br>
> and<br>
> DMLocalToGlobal().<br>
><br>
> Thanks,<br>
><br>
> Matt<br>
><br>
>><br>
>> I guess I'm suspicious because VecCreateGhost is supposed to<br>
>> internally set the mapping and it is supposed to position ghost nodes<br>
>> at the end of the array which I don't want it to do...<br>
>><br>
>> Thanks and sorry about the long email!<br>
><br>
><br>
><br>
<span class="HOEnZb"><font color="#888888">><br>
> --<br>
> What most experimenters take for granted before they begin their experiments<br>
> is infinitely more interesting than any results to which their experiments<br>
> lead.<br>
> -- Norbert Wiener<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <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
</div></div>