<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 6 June 2017 at 17:45, Franck Houssen <span dir="ltr"><<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div style="font-family:'times new roman','new york',times,serif;font-size:12pt;color:rgb(0,0,0)"><div>How to VecScatter from global to local vector, and then, VecGather back ?</div><div><br></div><div>This is a very simple use case: I need to split a global vector in local (possibly overlapping) pieces, then I need to modify each local piece (x2), and finally I need to assemble (+=) back local parts into a global vector.<br></div><div>Read the doc and went through examples... But still can't make this work: can I get some help on this ?<br></div><div><br></div></div></div></blockquote><div><br></div><div>Your usage of VecScatter in the code is fine.</div><div><br></div><div>The reason you don't get the expected result of (-2,-4,-2) is because your vector (<span style="font-family:Menlo;font-size:11px">globVec)</span> contains a bunch of -1's prior to the gather operation.</div><div><br></div><div>Just call</div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">  VecZeroEntries(globVec</span><span style="font-variant-ligatures:no-common-ligatures">);</span></p></div><div><span style="font-variant-ligatures:no-common-ligatures">before the call to </span></div><div><span style="font-variant-ligatures:no-common-ligatures"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">  VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">  VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);</span></p><div><span style="font-variant-ligatures:no-common-ligatures">and you'll get the correct result.</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">Thanks,</span></div><div><span style="font-variant-ligatures:no-common-ligatures">  Dave</span></div><div><br></div></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div style="font-family:'times new roman','new york',times,serif;font-size:12pt;color:rgb(0,0,0)"><div></div><div>Note: running petsc-3.7.6 on debian with gcc-6.3<br></div><div><br></div><div>Thanks,<br></div><div><br></div><div>Franck<br></div><div><br></div><div>~> head -n 12 vecScatterGather.cpp<br>// How to VecScatter from global to local vector, and then, VecGather back ?<br>//<br>//  global vector: 3x1           2 overlapping local vector: 2x1                    global vector: 3x1<br>//<br>//                            <wbr>                     x2<br>//                            <wbr>              |1    ->    |2<br>//           |1        scatter          |1            |2                gather               |2<br>//           |1          ->                            <wbr>                       ->                 |4<br>//           |1                            |1    ->    |2                                        |2<br>//                            <wbr>              |1            |2<br>//<br>// ~> g++ -o vecScatterGather.exe vecScatterGather.cpp -lpetsc -lm; mpirun -n 2 vecScatterGather.exe<br><br><br></div></div></div></blockquote></div><br></div></div>