[petsc-users] How to output the values of a parallel PETSc vector to a ASCII file
Feng-Chao Wang
wolfshow at gmail.com
Fri Dec 2 19:24:10 CST 2011
>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?
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?
>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]
... ... ...
******************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111203/c22bd550/attachment-0001.htm>
More information about the petsc-users
mailing list