[petsc-users] Example on using VecGetValues?

Barry Smith bsmith at mcs.anl.gov
Wed Jun 22 12:23:21 CDT 2016


  You need

 ierr = VecGetValues( petsc_b, 1, &row, &value );CHKERRQ(ierr);
                                                 ^^^^^^^^

previously you were asking for zero entries from the vector
   

> On Jun 22, 2016, at 9:35 AM, Faraz Hussain <faraz_hussain at yahoo.com> wrote:
> 
> I am trying to get my petsc vector of values into my c array of doubles. I tried this but it keeps giving value of 0:
> 
> 
> VecScatter ctx;
> VecScatterCreateToZero(petsc_x,&ctx,&petsc_b);
> VecScatterBegin(ctx,petsc_x,petsc_b,INSERT_VALUES,SCATTER_FORWARD);
> VecScatterEnd(ctx,petsc_x,petsc_b,INSERT_VALUES,SCATTER_FORWARD);
> VecScatterDestroy(&ctx);
> 
> VecView( petsc_b,PETSC_VIEWER_STDOUT_WORLD);
> 
> 
> PetscScalar   value;
>  for ( row=0; row < size ; row++ ) {
>        ierr = VecGetValues( petsc_b, 0, row, &value );CHKERRQ(ierr);
>        b[row] = value;
>        printf ( "Value is %.17g\n", b[row]);
>                                        }
> 
> It keeps printing this out, but the values should be real numbers, not 0:
> 
> Value is 0
> Value is 0
> Value is 0
> ....



More information about the petsc-users mailing list