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