[petsc-users] Vec entries altered incorrectly

Barry Smith bsmith at mcs.anl.gov
Sat Dec 17 10:53:22 CST 2011


   VecDuplicate does NOT copy the vector values over to the newly created vector. You must call VecCopy() after the VecDuplicate() if you want to copy the values over.

   Barry



On Dec 17, 2011, at 8:55 AM, Juha Jäykkä wrote:

> Hi all!
> 
> I am at a loss: my vector entries get zeroed when I am not even using the 
> vector.
> 
> I have the vectors:
> 
>  ierr = DACreateGlobalVector(lattice.da, &Fields); CHKERRQ(ierr);                                                      
>  ierr = VecDuplicate(Fields, &lattice.prev_state); CHKERRQ(ierr);
> ...
>  TSSolve(lattice.ts, Fields);
> 
> Later on, in a my RHS function PETSc has kindly provided me with my 
> "lattice.da" as part of my context (it is now called simply "da"), it has also 
> given me Fields, so I can do:
> 
>  DALocalInfo l_da;
>  ahcs_field    ***fields, ***rhs, ***pfields;
>  Vec           lfields, lpfields;
>  begin_using_petsc_DA_step_1(da, &l_da, Fields, &lfields, &fields);
> 
> where 
> 
> PetscErrorCode begin_using_petsc_DA_step_1(DA da, DALocalInfo *l_da, Vec 
> Fields, Vec *lfields, void *fields) {
> 
>  PetscErrorCode ierr;
>  ierr = DAGetLocalInfo(da, l_da); CHKERRQ(ierr);
>  ierr = DAGetLocalVector(da, lfields); CHKERRQ(ierr);
>  ierr = DAGlobalToLocalBegin(da, Fields, INSERT_VALUES, *lfields); 
> 
> At this point, the other vector in lattice.prev_state gets (some of) its 
> entries zeroed!
> 
> What am I doing wrong? Obviously, DAGlobalToLocalBegin working on Fields 
> should not alter anything in a duplicated vector, let alone INTERNAL values of 
> that vector (i.e. non-ghost points, which is what happens here).
> 
> Cheers,
> Juha
> 
> -- 
> 		 -----------------------------------------------
> 		| Juha Jäykkä, juhaj at iki.fi			|
> 		| http://www.maths.leeds.ac.uk/~juhaj		|
> 		 -----------------------------------------------



More information about the petsc-users mailing list