<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div><div> Depending on the serial library you may not need to split the vector into DMDA vectors with DMStagVecSplitToDMDA() for each component. Just global to natural and scatter to zero on the full vector, now the full vector is on the first rank and you can access what you need in that one vector if possible.</div> <br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Dec 6, 2023, at 6:37 PM, Colton Bryant <coltonbryant2021@u.northwestern.edu> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr"><div>Ah excellent! I was not aware of the ability to preallocate the objects and migrate them each time. <br></div><div><br></div><div>Thanks!</div><div>-Colton<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 6, 2023 at 5:18 PM Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Wed, Dec 6, 2023 at 5:54 PM Colton Bryant <<a href="mailto:coltonbryant2021@u.northwestern.edu" target="_blank">coltonbryant2021@u.northwestern.edu</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hello,</div><div><br></div><div>I am working on a code in which a DMSTAG object is used to solve a fluid flow problem and I need to gather this flow data on a single process to interact with an existing (serial) library at each timestep of my simulation. After looking around the solution I've tried is:</div><div><br></div><div>-use DMStagVecSplitToDMDA to extract vectors of each component of the flow</div><div>-use DMDACreateNaturalVector and DMDAGlobalToNatural to get the components naturally ordered</div><div>-use VecScatterCreateToZero to set up and then do the scatter to gather on the single process</div><div><br></div><div>Unless I'm misunderstanding something this method results in a lot of memory allocation/freeing happening at each step of the evolution and I was wondering if there is a way to directly perform such a scatter from the DMSTAG object without splitting as I'm doing here.</div></div></blockquote><div><br></div><div>1) You can see here:</div><div><br></div><div><a href="https://petsc.org/main/src/dm/impls/stag/stagda.c.html#DMStagVecSplitToDMDA" target="_blank">https://petsc.org/main/src/dm/impls/stag/stagda.c.html#DMStagVecSplitToDMDA</a></div><div><br></div><div>that this function is small. You can do the DMDA creation manually, and then just call <span style="">DMStagMigrateVecDMDA() each time, which will not create anything.</span></div><div><span style=""><br></span></div><div><span style="">2) You can create the natural vector upfront, and just scatter each time.</span></div><div><span style=""><br></span></div><div><span style="">3) You can create the serial vector upfront, and just scatter each time.</span></div><div><span style=""><br></span></div><div><span style="">This is some data movement. You can compress the g2n and 2zero scatters using</span></div><div><span style=""><br></span></div><div><span style=""> </span><a href="https://petsc.org/main/manualpages/PetscSF/PetscSFCompose/" target="_blank">https://petsc.org/main/manualpages/PetscSF/PetscSFCompose/</a></div><div><br></div><div>as an optimization.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Any advice would be much appreciated!</div><div><br></div><div>Best,</div><div>Colton Bryant <br></div></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>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><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote></div>
</div></blockquote></div><br></body></html>