[petsc-users] output vec

likunt at caltech.edu likunt at caltech.edu
Thu May 22 09:32:10 CDT 2014


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. 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).  Thanks.





More information about the petsc-users mailing list