[petsc-users] VecGetValues and VecGetArray return nothing but zeros
Jed Brown
jed at jedbrown.org
Thu Sep 8 11:28:08 CDT 2016
Tonio Herrmann <tonioherrmann at gmail.com> writes:
> Hello,
> during my attempts to learn PETSc, I am trying to understand the relation
> between global and local vectors on a DMDA. There is a problem in my code
> below, which only returns zeros when I try to access the local values,
> although VecView shows that the values are correctly transferred from the
> global vector g to the local vector l.
> Is it obvious, what I am doing wrong?
>
> Another question, I was expecting that "VecView(l,PETSC_VIEWER_STDOUT_WORLD);"
> would print l synchronized from each process, but only l from process #0 is
> shown. How can I see the other parts of l?
They're there, you just botched the format string.
> PetscSynchronizedPrintf(PETSC_COMM_WORLD,"VecGetValues on rank
> %d:\n",rank);
> for (int k=0;k<sz;k++) PetscSynchronizedPrintf(PETSC_COMM_WORLD,"%d
> ",data[k]);
%d is for integers, but you're passing scalars. Use %g or %f, for example.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160908/133dd597/attachment-0001.pgp>
More information about the petsc-users
mailing list