<div dir="ltr">I am not sure if <span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">VecDuplicate is <span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">problematic. But we should avoid collective calls in general. They do more harm than VecScatters, which are often neighborhood and do not sync all processors.</span></span></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">--Junchao Zhang</div></div></div>
<br><div class="gmail_quote">On Tue, Jun 19, 2018 at 9:16 PM, Smith, Barry F. <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"><br>
Jed,<br>
<br>
You added these two lines. Any idea why they are needed?<br>
<br>
Thanks<br>
<br>
Barry<br>
<br>
3e08d2bebf99 src/dm/impls/da/dadist.c (Barry Smith 2012-09-18 14) PetscFunctionBegin;<br>
c688c0463f6c src/dm/impls/da/dadist.c (Matthew Knepley 2012-11-11 15) ierr = VecGetDM(g, &da);CHKERRQ(ierr);<br>
2dcb2ebcaafe src/dm/impls/da/dadist.c (Barry Smith 2010-10-31 16) ierr = DMCreateGlobalVector(da,gg);<wbr>CHKERRQ(ierr);<br>
077aedaf8cb5 src/dm/impls/da/dadist.c (Jed Brown 2013-02-11 17) ierr = VecGetLayout(g,&map);CHKERRQ(<wbr>ierr);<br>
077aedaf8cb5 src/dm/impls/da/dadist.c (Jed Brown 2013-02-11 18) ierr = VecSetLayout(*gg,map);CHKERRQ(<wbr>ierr);<br>
2dcb2ebcaafe src/dm/impls/da/dadist.c (Barry Smith 2010-10-31 19) PetscFunctionReturn(0)<br>
<br>
<br>
If we were a bit more clever we could probably avoid all communication in VecDuplicate() but is it worth bothering unless we know it is problematic<br>
<div><div class="h5"><br>
> On Jun 19, 2018, at 4:30 PM, Junchao Zhang <<a href="mailto:jczhang@mcs.anl.gov">jczhang@mcs.anl.gov</a>> wrote:<br>
> <br>
> I met an expensive VecDuplicate. See the attached call stack. VecDuplicate_MPI_DA indirectly calls MPI_Allreduce/Allgather to build the vector's layout, but it then immediately destroys it with VecGetLayout & VecSetLayout. Is it wrong?<br>
> src/dm/impls/da/dadist.c<br>
> PetscErrorCode VecDuplicate_MPI_DA(Vec g,Vec *gg)<br>
> {<br>
> PetscErrorCode ierr;<br>
> DM da;<br>
> PetscLayout map;<br>
> <br>
> PetscFunctionBegin;<br>
> ierr = VecGetDM(g, &da);CHKERRQ(ierr);<br>
> ierr = DMCreateGlobalVector(da,gg);<wbr>CHKERRQ(ierr);<br>
> ierr = VecGetLayout(g,&map);CHKERRQ(<wbr>ierr);<br>
> ierr = VecSetLayout(*gg,map);CHKERRQ(<wbr>ierr);<br>
> PetscFunctionReturn(0);<br>
> }<br>
> <br>
> --Junchao Zhang<br>
</div></div>> <VecDup.png><br>
<br>
</blockquote></div><br></div>