[petsc-users] output vec

Matthew Knepley knepley at gmail.com
Thu May 22 10:20:42 CDT 2014


On Thu, May 22, 2014 at 10:02 AM, Likun Tan <likunt at caltech.edu> wrote:

> Thanks for your suggestion.
> Using VecView or PetscViewerBinaryWrite will print the vec vertically, i.e.
>

No it won't. Binary files have no newlines or spaces.

   Matt


> m1
> m2
> m3
> m4
> m5
> m6
>
> But I prefer the form
>
> m1 m2 m3
> m4 m5 m6
>
> Since in the end I will have about 1e+7 elements in the vec. If there is
> no way to output the vec in the second form, I will simply use VecView.
> Thanks.
>
> On May 22, 2014, at 10:42 AM, Matthew Knepley <knepley at gmail.com> wrote:
>
> On Thu, May 22, 2014 at 9:32 AM, <likunt at caltech.edu> wrote:
>
>> 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.
>>
>
> There is PetscViewerBindaryWrite(), but what do you really want to do?
> What you suggest
> doing will be very slow. Why not just use PETSc binary output?
>
>    Matt
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140522/b84093a5/attachment-0001.html>


More information about the petsc-users mailing list