[petsc-users] normalization of a vector

Barry Smith bsmith at mcs.anl.gov
Thu May 8 12:44:33 CDT 2014


   Use VecGetArray(). Loop over each the 3 tuples doing the normalization and then use VecRestoreArray(). VecGetArray/RestoreArray() do not copy values so are much faster than VecGetValues().   

   Barry

  Each process will just loop over its local part of the vector.


On May 8, 2014, at 11:08 AM, likunt at caltech.edu wrote:

> Dear Petsc developers,
> 
> I have a vector V={u1, u2, u3, v1, v2, v3}. I need to normalize each 3d
> vector  and reset V, i.e.
> 
> V={u1/|u|, u2/|u|, u3/|u|, v1/|v|, v2/|v|, v3/|v|},
> with |u| and |v| denotes the magnitudes of {u1,u2,u3} and {v1,v2,v3}.
> 
> I tried
> 
> VecGetValues(V, 3, col, val);
> normalization of val;
> VecSetValues(V, 3, col, val, INSERT_VALUES);
> 
> but I got the error message
> 
> PETSC ERROR: Object is in wrong state!
> PETSC ERROR: You have already added values; you cannot now insert!
> 
> Is there any fast way to do that? Thanks.
> 
> 



More information about the petsc-users mailing list