[petsc-users] How to output the values of a parallel PETSc vector to a ASCII file

Matthew Knepley knepley at gmail.com
Fri Dec 2 19:29:18 CST 2011


2011/12/2 Feng-Chao Wang <wolfshow at gmail.com>

> **
> >Date: Fri, 2 Dec 2011 08:07:54 -0600
>  >From: Jed Brown <jedbrown at mcs.anl.gov>
> >Subject: Re: [petsc-users] How to output the values of a parallel
> >PETSc vector to a ASCII file
> >To: PETSc users list <petsc-users at mcs.anl.gov>
> >Message-ID:
> <CAM9tzSkSeN3Z11vdadF66XTe_KVbUo-eA=2hvAgROFkTJfsYZg at mail.gmail.com>
> >Content-Type: text/plain; charset="utf-8"
>  >On Fri, Dec 2, 2011 at 08:04, Feng-Chao Wang <wolfshow at gmail.com> wrote:
>  > **
> > Dear all,
> >
> > I intend to postprocess the solution of a PDE (stored in a
>
> > parallel PETSc vector ) using tecplot. Thus I want to  output the values of
>
> > the parallel vector as well as other data (such as the grid information) to
> > a ASCII file.
> >
> > When I deal this with
> >
> > VecGetArray(U, &u);
> >
> > for (i=0; i<Mx*My; i++)
> > {
> > PetscViewerASCIIPrintf(viewer,"%F %F %F", x, y, u[i]);
> > }
> >
> > If more than 1 processor are used, I found that only part of the value of
> > u was output correctly (that stored on the first processor).
> > I found in the manual page of "PetscViewerASCIIPrintf" that "Not
> > Collective, but only first processor in set has any effect"
> >
>  >If you can afford the memory:
>  >
> http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Vec/VecScatterCreateToZero.html
>
> Thank you very much!
> I tried the Scatter method. I found that even I scatter the parallel
> vector to a sequential vector, when I want to output this sequential vector
> to the file, I still can not use
> "PetscViewerASCIIPrintf(viewer,"%F %F %F", x, y, u[i]);", because the
> vector can not be directly accessed for output?
>

Yes, it is an object. You really must read the manual chapter on Vec
objects.


>
>  Thus I used VecGetArray(U, &u); and then PetscViewerASCIIPrintf. I still
> got part of the sequential vector, because the array u is stored on all the
> processor?
>

This is incorrect. The entire array resides on process zero

  Matt

> >Slower:
>  >
> http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Sys/PetscSynchronizedPrintf.html
>
> I tried the PetscSynchronizedPrintf and got the same result. As a beginner
> of PETSc, I wonder if I can output the value of a vector U to the ASCII
> file using Printf("%f", U[i])?
> If so, I can get the result I want.
>
> Or, I must use VecGetArray(U, &u); before I want to access the data stored
> in the vector?
>
> Thank you!
>
>  >Binary output can be written in parallel using
>  >http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Vec/VecView.html
>
> Yes, the VecView can output the correct data stored in the parallel vector
> to a ASCII file. However, I want to output not only the vector value but
> also the grid information according to the tecplot file format, for
> example, there are three column of data in one file:
>
> x[0] y[0] vec_value[0]
> x[1] y[1] vec_value[1]
> x[2] y[2] vec_value[2]
> x[3] y[3] vec_value[3]
> x[4] y[4] vec_value[4]
> x[5] y[5] vec_value[5]
> ...   ...    ...
>
>
>
> ******************************************
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111202/bf1670d8/attachment.htm>


More information about the petsc-users mailing list