[petsc-users] Troubles with VecScatter routines: inverting vectors values

Matthew Knepley knepley at gmail.com
Tue May 24 11:37:02 CDT 2016


On Tue, May 24, 2016 at 11:22 AM, Alice Raeli <
alice.raeli at math.u-bordeaux.fr> wrote:

> Hi All,
>
> I had the necessity to read data on another node of a Vector Petsc.
> I followed the structure showed in the tutorial of VecScatterCreateToAll.
> I call the function below 2 times with 2 different vectors vec1 and vec2.
>
> void Scatter(Vec vec, PetscScalar &value, vector<int> NeighboursIndex, int
> NeighNumber){
>
>
>     Vec V_SEQ;
>     VecScatter ctx;
>     PetscScalar *vecArray;
>
>
>     VecScatterCreateToAll(vec,&ctx,&V_SEQ);
>     VecScatterBegin(ctx,vec,V_SEQ,INSERT_VALUES,SCATTER_FORWARD);
>     VecScatterEnd(ctx,vec,V_SEQ,INSERT_VALUES,SCATTER_FORWARD);
>     ierr = VecGetArray(V_SEQ,&vecArray);
>     for(int i=0; i<NeighNumber;i++){
>         PetscInt index=NeighboursIndex[i];
>         value = vecArray[index];
>
>         if(NeighboursIndex[0]==869 && (index==363 || index == 364 || index
> ==365) ){
>             cout << endl << index << "  inside function " << value;
>         }
>
>     }
>     //
>     ierr = VecRestoreArray(V_SEQ,&vecArray);
>     VecScatterDestroy(&ctx);
>     VecDestroy(&V_SEQ);
>     return;
> }
>
> When I run my code with one node i have a result coherent but if I use 2
> nodes the vectors are inverted in values.
>

VecScatter just sends values. It does not process them in any way. You must
have other code in your program
that is altering the values. If you can send a small example, we will look
at it.

  Thanks,

     Matt


> I used for a test a vector of 1 and a vector of 0 and I concentrated the
> output on a point that communicates with the other node.
>
> Can you explain me what is effectively wrong when I call the vecscatter
> routines? I can’t see a reason coherent with a simple inversion of values
> from 2 vectors.
>
> Example of output
> 1 node:
> first call vec1
> 364  inside function 87.797
> 363  inside function 89.0416
> 365  inside function 86.4618
> second call vec2
> 364  inside function 0.0268704
> 363  inside function 0.0322394
> 365  inside function 0.0199141
>
> 2 nodes:
> first call vec1
> 364  inside function 0.0268704
> 363  inside function 0.0322394
> 365  inside function 0.0199141
> second call vec2
> 364  inside function 87.797
> 363  inside function 89.0416
> 365  inside function 86.4618
>
> *Many Thanks*
> *Alice Raeli*
> *I*nstitut de *M*athématiques de *B*ordeaux *(IMB)*
>
> alice.raeli at math.u-bordeaux1.fr
>
> alice.raeli at u-bordeaux.fr
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160524/87510a28/attachment.html>


More information about the petsc-users mailing list