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

2023-01-05 Thread Barry Smith

  Note there is also VecSetValuesLocal() that takes ghosted local indices 
(ghosted local indices are different from your meaning of "local indices"). See 
https://petsc.org/release/docs/manualpages/Vec/VecSetValuesLocal/  
https://petsc.org/release/docs/manualpages/Vec/VecSetLocalToGlobalMapping/

  Barry


> On Jan 5, 2023, at 12:41 PM, Alfredo Jaramillo  
> wrote:
> 
> omg... for some reason I was thinking it takes local indices. Yes.. modifying 
> that line the code works well.
> 
> thank you!
> Alfredo
> 
> On Thu, Jan 5, 2023 at 10:38 AM Junchao Zhang  > wrote:
>> VecSetValue() also needs global indices, so you need PetscInt gl_row = 
>> (PetscInt)(i)+rstart; 
>> 
>> --Junchao Zhang
>> 
>> 
>> On Thu, Jan 5, 2023 at 11:25 AM Alfredo Jaramillo > > wrote:
>>> dear PETSc developers,
>>> 
>>> I have a code where I copy an array to a distributed petsc vector with the 
>>> next lines:
>>> 
>>> 1for (int i = 0; i < ndof_local; i++) {
>>> 2PetscInt gl_row = (PetscInt)(i)+rstart;
>>> 3PetscScalar val = (PetscScalar)u[i];
>>> 4VecSetValues(x,1,_row,,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



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

2023-01-05 Thread Alfredo Jaramillo
omg... for some reason I was thinking it takes local indices. Yes..
modifying that line the code works well.

thank you!
Alfredo

On Thu, Jan 5, 2023 at 10:38 AM Junchao Zhang 
wrote:

> VecSetValue() also needs global indices, so you need PetscInt gl_row = (
> PetscInt)(i)+rstart;
>
> --Junchao Zhang
>
>
> On Thu, Jan 5, 2023 at 11:25 AM Alfredo Jaramillo <
> ajaramillopa...@gmail.com> wrote:
>
>> 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,_row,,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
>>
>


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

2023-01-05 Thread Junchao Zhang
VecSetValue() also needs global indices, so you need PetscInt gl_row = (
PetscInt)(i)+rstart;

--Junchao Zhang


On Thu, Jan 5, 2023 at 11:25 AM Alfredo Jaramillo 
wrote:

> 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,_row,,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
>


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

2023-01-05 Thread Alfredo Jaramillo
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,_row,,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