[petsc-users] Insertion mode for Scatter
Pierre Jolivet
pierre at joliv.et
Fri Jun 13 04:43:15 CDT 2025
> On 13 Jun 2025, at 11:32 AM, SCOTTO Alexandre via petsc-users <petsc-users at mcs.anl.gov> wrote:
>
> Dear PETSc community,
>
> I am currently struggling with the ADD_VALUE mode of the Scatter object. Here is a simple piece of (Python) code to illustrate the issue:
>
> vec_1 = PETSc.Vec().createMPI(size=10)
> vec_1.shift(2.0)
>
> vec_2 = PETSc.Vec().createMPI(size=10)
> vec_2.shift(1.0)
>
> index_set = PETSc.IS().createStride(10, step=1)
>
> scatter = PETSc.Scatter().create(vec_1, index_set, vec_2, index_set)
> scatter.scatter(vec_1, vec_2, addv=True)
>
> Vectors vec_1 and vec_2 are respectively filled-in with 2.0 and 1.0. After the scattering, I would expect to have in vec_2 the sum of the values initially in vec_2 (that is 1.0) plus the values coming from vec_1 (that is 2.0).
>
> But instead of having vec_2 filled in with 3.0 it is filled-in with 9.0. My understanding is that the number of processes (here 4 processes) plays a role since 9.0 = 1.0 (initial value) + 2.0 (values coming from vec_1) x 4 (number of processes).
>
> Is there a way to have simply 3.0 as a result?
With the index_set you are supplying, you are basically saying that each process should scatter the complete vector (not just its local portion).
If you use an index_set which does not induce communication (e.g., of size the local size of the Vec and with the same start as the first local row of the Vec), then you’ll get 3.0 as a result.
Thanks,
Pierre
> Hoping to have been clear enough, best regards,
> Alexandre.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250613/b796607b/attachment-0001.html>
More information about the petsc-users
mailing list