[petsc-users] How to VecScatter from global to local vector, and then, VecGather back ?

Dave May dave.mayhem23 at gmail.com
Tue Jun 6 14:02:08 CDT 2017


On 6 June 2017 at 17:45, Franck Houssen <franck.houssen at inria.fr> wrote:

> How to VecScatter from global to local vector, and then, VecGather back ?
>
> 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.
> Read the doc and went through examples... But still can't make this work:
> can I get some help on this ?
>
>
Your usage of VecScatter in the code is fine.

The reason you don't get the expected result of (-2,-4,-2) is because your
vector (globVec) contains a bunch of -1's prior to the gather operation.

Just call

  VecZeroEntries(globVec);
before the call to

  VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);

  VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
and you'll get the correct result.

Thanks,
  Dave




> Note: running petsc-3.7.6 on debian with gcc-6.3
>
> Thanks,
>
> Franck
>
> ~> head -n 12 vecScatterGather.cpp
> // How to VecScatter from global to local vector, and then, VecGather back
> ?
> //
> //  global vector: 3x1           2 overlapping local vector:
> 2x1                    global vector: 3x1
> //
> //                                                 x2
> //                                          |1    ->    |2
> //           |1        scatter          |1            |2
> gather               |2
> //           |1          ->
>     ->                 |4
> //           |1                            |1    ->    |2
>                       |2
> //                                          |1            |2
> //
> // ~> g++ -o vecScatterGather.exe vecScatterGather.cpp -lpetsc -lm; mpirun
> -n 2 vecScatterGather.exe
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170606/bce23c12/attachment.html>


More information about the petsc-users mailing list