[petsc-users] setting a vector with VecSetValue versus VecSetValues

Alfredo Jaramillo ajaramillopalma at gmail.com
Thu Jan 5 11:25:08 CST 2023


dear PETSc developers,

I have a code where I copy an array to a distributed petsc vector with the
next lines:

1 for (int i = 0; i < ndof_local; i++) {
2 PetscInt gl_row = (PetscInt)(i)+rstart;
3 PetscScalar val = (PetscScalar)u[i];
4 VecSetValues(x,1,&gl_row,&val,INSERT_VALUES);
5 }

// for (int i = 0; i < ndof_local; i++) {
// PetscInt gl_row = (PetscInt)(i);
// PetscScalar val = (PetscScalar)u[i];
// VecSetValue(x,gl_row,val,INSERT_VALUES);
// }

VecAssemblyBegin(x);
VecAssemblyEnd(x);

This works as expected. If, instead of using lines 1-5, I use the lines
where VecSetValue is used with local indices, then the vector is null on
all the processes but rank 0, and the piece of information at rank zero is
incorrect.

What could I be doing wrong?

bests regards
Alfredo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230105/994b4708/attachment.html>


More information about the petsc-users mailing list