[petsc-users] Insertion mode for Scatter

Pierre Jolivet pierre at joliv.et
Fri Jun 13 04:58:32 CDT 2025


Please always keep the list in copy.

> On 13 Jun 2025, at 11:55 AM, SCOTTO Alexandre <alexandre.scotto at irt-saintexupery.com> wrote:
> 
> Hello Pierre,
>  
> Thank you for you answer.
>  
> I think I see the subtlety here, and it makes realized that I have not properly understood yet how index sets should be manipulated, in particular whether the provided indices are local or global.
>  
> It seems that this code solves my issue:
>  
> index_set_1 = PETSc.IS().createStride(
>     vec_1.local_size, first=vec_1.owner_range[0], step=1
> )
> index_set_2 = PETSc.IS().createStride(
>     vec_2.local_size, first=vec_2.owner_range[0], step=1
> )
>  
> scatter = PETSc.Scatter().create(vec_1, index_set_1, vec_2, index_set_2)
> scatter.scatter(vec_1, vec_2, addv=True)
>  
> Do you think that this is a decent manner of transfering the whole content of a vector to another of same dimension?
>  
> I have a lot of this scattering to perform so if you have a better recommendation I would be pleased.

The “scattering” you are defining and using is basically a VecAXPY(), so using a scatter for such an operation is definitely _not_ the way to go.

Thanks,
Pierre

> Best regards,
> Alexandre.
>  
>  
> De : Pierre Jolivet <pierre at joliv.et>
> Envoyé : vendredi 13 juin 2025 11:43
> À : SCOTTO Alexandre <alexandre.scotto at irt-saintexupery.com>
> Cc : petsc-users at mcs.anl.gov
> Objet : Re: [petsc-users] Insertion mode for Scatter
>  
>  
> 
> 
> On 13 Jun 2025, at 11:32 AM, SCOTTO Alexandre via petsc-users <petsc-users at mcs.anl.gov <mailto: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/26daa28f/attachment-0001.html>


More information about the petsc-users mailing list