<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.6000.17080" name=GENERATOR>
<STYLE>@font-face {
        font-family: ËÎÌå;
}
@font-face {
        font-family: Verdana;
}
@font-face {
        font-family: @ËÎÌå;
}
@page Section1 {size: 595.3pt 841.9pt; margin: 72.0pt 90.0pt 72.0pt 90.0pt; layout-grid: 15.6pt; }
P.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; FONT-SIZE: 10.5pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; TEXT-ALIGN: justify
}
LI.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; FONT-SIZE: 10.5pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; TEXT-ALIGN: justify
}
DIV.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; FONT-SIZE: 10.5pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; TEXT-ALIGN: justify
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
        FONT-WEIGHT: normal; COLOR: windowtext; FONT-STYLE: normal; FONT-FAMILY: Verdana; TEXT-DECORATION: none; mso-style-type: personal-compose
}
DIV.Section1 {
        page: Section1
}
UNKNOWN {
        FONT-SIZE: 10pt
}
BLOCKQUOTE {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em
}
OL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
UL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
</STYLE>
</HEAD>
<BODY style="FONT-SIZE: 10pt; MARGIN: 10px; FONT-FAMILY: verdana">
<DIV><FONT face=Verdana
size=2>>Date: Fri, 2 Dec 2011 08:07:54 -0600</DIV>
<DIV>
<DIV>>From: Jed Brown <jedbrown@mcs.anl.gov></DIV>
<DIV>>Subject: Re: [petsc-users] How to output the values of a parallel</DIV>
<DIV>>PETSc vector to a ASCII file</DIV>
<DIV>>To: PETSc users list <petsc-users@mcs.anl.gov></DIV>
<DIV>>Message-ID:</DIV>
<DIV><CAM9tzSkSeN3Z11vdadF66XTe_KVbUo-eA=2hvAgROFkTJfsYZg@mail.gmail.com></DIV>
<DIV>>Content-Type: text/plain; charset="utf-8"</DIV>
<DIV></DIV>
<DIV>>On Fri, Dec 2, 2011 at 08:04, Feng-Chao Wang <wolfshow@gmail.com> wrote:</DIV>
<DIV></DIV>
<DIV>> **</DIV>
<DIV>> Dear all,</DIV>
<DIV>></DIV>
<DIV>> I intend to postprocess the solution of a PDE (stored in a</DIV>
<DIV>> parallel PETSc vector ) using tecplot. Thus I want to output the values of</DIV>
<DIV>> the parallel vector as well as other data (such as the grid information) to</DIV>
<DIV>> a ASCII file.</DIV>
<DIV>></DIV>
<DIV>> When I deal this with</DIV>
<DIV>></DIV>
<DIV>> VecGetArray(U, &u);</DIV>
<DIV>></DIV>
<DIV>> for (i=0; i<Mx*My; i++)</DIV>
<DIV>> {</DIV>
<DIV>> PetscViewerASCIIPrintf(viewer,"%F %F %F", x, y, u[i]);</DIV>
<DIV>> }</DIV>
<DIV>></DIV>
<DIV>> If more than 1 processor are used, I found that only part of the value of</DIV>
<DIV>> u was output correctly (that stored on the first processor).</DIV>
<DIV>> I found in the manual page of "PetscViewerASCIIPrintf" that "Not</DIV>
<DIV>> Collective, but only first processor in set has any effect"</DIV>
<DIV>></DIV>
<DIV></DIV>
<DIV>>If you can afford the memory:</DIV>
<DIV></DIV>
<DIV>>http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Vec/VecScatterCreateToZero.html</DIV>
<DIV> </DIV>
<DIV>Thank you very much!</DIV>
<DIV>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?</DIV>
<DIV> </DIV>
<DIV> 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?</DIV>
<DIV> </DIV>
<DIV>>Slower:</DIV>
<DIV></DIV>
<DIV>><A
href="http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Sys/PetscSynchronizedPrintf.html">http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Sys/PetscSynchronizedPrintf.html</A></DIV>
<DIV> </DIV>
<DIV>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])? </DIV>
<DIV>If so, I can get the result I want.</DIV>
<DIV> </DIV>
<DIV>Or, I must use VecGetArray(U, &u); before I want to access the
data stored in the vector?</DIV>
<DIV> </DIV>
<DIV>Thank you!</DIV>
<DIV> </DIV>
<DIV></DIV>
<DIV>>Binary output can be written in parallel using</DIV>
<DIV></DIV>
<DIV>><A
href="http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Vec/VecView.html">http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Vec/VecView.html</A></DIV>
<DIV> </DIV>
<DIV>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:</DIV>
<DIV> </DIV>
<DIV>x[0] y[0] vec_value[0]</DIV>
<DIV>x[1] y[1] vec_value[1]</DIV>
<DIV>x[2] y[2] vec_value[2]</DIV>
<DIV>x[3] y[3] vec_value[3]</DIV>
<DIV>x[4] y[4] vec_value[4]</DIV>
<DIV>x[5] y[5] vec_value[5]</DIV>
<DIV>... ... ...</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>******************************************</DIV></FONT></DIV></BODY></HTML>