<div dir="ltr">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I see. Thanks for the explanation.</span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">Yes, that's the stage I'm in now. I am developing the code and only testing+validating small samples, so I am trying to visualize the results in Matlab. But in the future, Matlab will probably not be feasible so I will probably need to use the binary format and visualize in Avizo.</div><br class="gmail-Apple-interchange-newline">
<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 7, 2018 at 2:29 PM, Smith, Barry F. <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Here is the code VecView_MPI_ASCII()<br>
<br>
if (format == PETSC_VIEWER_ASCII_INDEX) {<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%D: ",cnt++);CHKERRQ(ierr);<br>
}<br>
#if defined(PETSC_USE_COMPLEX)<br>
if (PetscImaginaryPart(xarray[i]) > 0.0) {<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%g + %g i\n",(double)PetscRealPart(<wbr>xarray[i]),(double)<wbr>PetscImaginaryPart(xarray[i]))<wbr>;CHKERRQ(ierr);<br>
} else if (PetscImaginaryPart(xarray[i]) < 0.0) {<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%g - %g i\n",(double)PetscRealPart(<wbr>xarray[i]),-(double)<wbr>PetscImaginaryPart(xarray[i]))<wbr>;CHKERRQ(ierr);<br>
} else {<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%g\n",(double)PetscRealPart(<wbr>xarray[i]));CHKERRQ(ierr);<br>
}<br>
#else<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%g\n",(double)xarray[i]);<wbr>CHKERRQ(ierr);<br>
#endif<br>
}<br>
/* receive and print messages */<br>
for (j=1; j<size; j++) {<br>
ierr = MPI_Recv(values,(PetscMPIInt)<wbr>len,MPIU_SCALAR,j,tag,<wbr>PetscObjectComm((PetscObject)<wbr>xin),&status);CHKERRQ(ierr);<br>
ierr = MPI_Get_count(&status,MPIU_<wbr>SCALAR,&n);CHKERRQ(ierr);<br>
if (format != PETSC_VIEWER_ASCII_COMMON) {<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"Process [%d]\n",j);CHKERRQ(ierr);<br>
}<br>
for (i=0; i<n; i++) {<br>
if (format == PETSC_VIEWER_ASCII_INDEX) {<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%D: ",cnt++);CHKERRQ(ierr);<br>
}<br>
#if defined(PETSC_USE_COMPLEX)<br>
if (PetscImaginaryPart(values[i]) > 0.0) {<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%g + %g i\n",(double)PetscRealPart(<wbr>values[i]),(double)<wbr>PetscImaginaryPart(values[i]))<wbr>;CHKERRQ(ierr);<br>
} else if (PetscImaginaryPart(values[i]) < 0.0) {<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%g - %g i\n",(double)PetscRealPart(<wbr>values[i]),-(double)<wbr>PetscImaginaryPart(values[i]))<wbr>;CHKERRQ(ierr);<br>
} else {<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%g\n",(double)PetscRealPart(<wbr>values[i]));CHKERRQ(ierr);<br>
}<br>
#else<br>
ierr = PetscViewerASCIIPrintf(viewer,<wbr>"%g\n",(double)values[i]);<wbr>CHKERRQ(ierr);<br>
#endif<br>
}<br>
}<br>
<br>
So each process ships its values to process zero who prints them in order.<br>
<br>
Note that printing out vectors and matrices as ASCII is just for toys and to help debug. For large runs one should always use some variant of binary output.<br>
<span class="HOEnZb"><font color="#888888"><br>
Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
> On Feb 7, 2018, at 1:08 PM, Paula Sanematsu <<a href="mailto:paulasan@gmail.com">paulasan@gmail.com</a>> wrote:<br>
><br>
> I am using PETSc 3.7.6 and Fortran.<br>
><br>
> I am trying to output a PETSc vector that contains the solution of a linear system. I am using VecView with the PETSC_VIEWER_ASCII_INDEX format as follows:<br>
><br>
> call PetscViewerASCIIOpen(PETSC_<wbr>COMM_WORLD,"output.dat",<wbr>viewer,ierr)<br>
> call PetscViewerPushFormat(viewer,<wbr>PETSC_VIEWER_ASCII_INDEX,ierr)<br>
> call VecView(myVec,viewer,ierr)<br>
><br>
> When I run with 4 processors, my output file looks like:<br>
><br>
> Vec Object: 4 MPI processes<br>
> type: mpi<br>
> Process [0]<br>
> 0: 30.7501<br>
> 1: 164.001<br>
> 2: 41.0001<br>
> 3: 164.001<br>
> .<br>
> .<br>
> .<br>
> Process [1]<br>
> 4988: 60.1443<br>
> 4989: 157.257<br>
> 4990: 271.518<br>
> 4991: 366.669<br>
> .<br>
> .<br>
> .<br>
> Process [2]<br>
> 9977: 114.948<br>
> 9978: -77.2896<br>
> 9979: 823.142<br>
> 9980: -1096.19<br>
> .<br>
> .<br>
> .<br>
> Process [3]<br>
> 14916: 0.<br>
> 14917: 4.4056<br>
> 14918: 2.08151<br>
> 14919: -0.110862<br>
> .<br>
> .<br>
> .<br>
> 19843: 0.<br>
><br>
> My question is: each processor outputs the part of the vector that it owns? Or does PETSc collects each processor's parts and then processor 0 sequentially outputs the 1st quarter of the global vector, processor 1 outputs the 2nd quarter of the global vector, processor 2 outputs the 3rd quarter of the global vector, and so on? Or, does PETSc do something else?<br>
><br>
> Thank you!<br>
><br>
> Paula<br>
><br>
<br>
</div></div></blockquote></div><br></div>