[petsc-users] output vec
Jed Brown
jed at jedbrown.org
Thu May 22 09:42:41 CDT 2014
likunt at caltech.edu writes:
> Dear Petsc developers,
>
> I am trying to output my vec M={m1 m2 m3 m4 m5 m6 ...} in a form like this:
>
> m1 m2 m3
> m4 m5 m6
> ...
>
> Here is my code to do this:
>
> ==================================================================
> PetscViewerASCIIOpen(PETSC_COMM_WORLD, NAME, &view);
> PetscViewerSetFormat(view, PETSC_VIEWER_ASCII_SYMMODU);
> PetscViewerASCIISynchronizedAllow(view, PETSC_TRUE);
> for(int step=0; step<STEP; step++)
> {
> //calculate M at current step
> DMDAVecGetArray(da, M, &aM);
> DMDAGetCorners(da, &xs, 0, 0, &xm, 0, 0);
> for(int node=xs; node<xs+xm; node++)
> {
> PetscViewerASCIISynchronizedPrintf(view, "%3.12f %3.12f %3.12f\n",
> aM[node].x, aM[node].y, aM[node].z);
> PetscViewerFlush(view);
> }
> DMDAVecRestoreArray(da, M, &aM);
> }
> =================================================================
>
> but this turns out to be very slow.
Yes, ASCII output is slow.
> I am trying to write it in a binary file, but I cannot find the
> corresponding functionality (such as PETSC_VIEWER_ASCII_SYMMODU and
> PetscViewerASCIISynchronizedPrintf in binary form).
Just use VecView to a binary viewer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140522/ff026a65/attachment.pgp>
More information about the petsc-users
mailing list