[petsc-users] Example on using VecGetValues?

Faraz Hussain faraz_hussain at yahoo.com
Wed Jun 22 09:35:37 CDT 2016


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