2011/12/2 Feng-Chao Wang <span dir="ltr"><<a href="mailto:wolfshow@gmail.com">wolfshow@gmail.com</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<u></u>
<div style="FONT-SIZE:10pt;MARGIN:10px;FONT-FAMILY:verdana">
<div><font face="Verdana" size="2">>Date: Fri, 2 Dec 2011 08:07:54 -0600</font></div>
<div>
<div>>From: Jed Brown <<a href="mailto:jedbrown@mcs.anl.gov" target="_blank">jedbrown@mcs.anl.gov</a>></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 <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>></div>
<div>>Message-ID:</div>
<div><CAM9tzSkSeN3Z11vdadF66XTe_KVbUo-eA=<a href="mailto:2hvAgROFkTJfsYZg@mail.gmail.com" target="_blank">2hvAgROFkTJfsYZg@mail.gmail.com</a>></div>
<div>>Content-Type: text/plain; charset="utf-8"</div>
<div></div>
<div>>On Fri, Dec 2, 2011 at 08:04, Feng-Chao Wang <<a href="mailto:wolfshow@gmail.com" target="_blank">wolfshow@gmail.com</a>> 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>><a href="http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Vec/VecScatterCreateToZero.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Vec/VecScatterCreateToZero.html</a></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></blockquote><div><br></div><div>Yes, it is an object. You really must read the manual chapter on Vec objects.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="FONT-SIZE:10pt;MARGIN:10px;FONT-FAMILY:verdana"><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></blockquote><div><br></div><div>This is incorrect. The entire array resides on process zero</div><div><br></div><div> Matt </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="FONT-SIZE:10pt;MARGIN:10px;FONT-FAMILY:verdana"><div>
<div>>Slower:</div>
<div></div>
<div>><a href="http://www.mcs.anl.gov/petsc/petsc-dev/docs/manualpages/Sys/PetscSynchronizedPrintf.html" target="_blank">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" target="_blank">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></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>