output to matlab readable format
Barry Smith
bsmith at mcs.anl.gov
Tue Feb 24 15:45:05 CST 2009
No it is not. The (row, column, value) format is a silly relic
from the 1980s; it is completely unscalable and slow to parse.
For SEQAIJ matrices you can use the matrix format
PETSC_VIEWER_ASCII_MATRIXMARKET to print the matrix. But it is not
supported for other matrices types (though could be easily added). I
don't know which is sadder, that other formats don't support it or
that someone actually added it for SeqAIJ :-(
Barry
On Feb 24, 2009, at 3:40 PM, Matthew Knepley wrote:
> That is the default ASCII format.
>
> Matt
>
> On Tue, Feb 24, 2009 at 2:55 PM, Yixun Liu <enjoywm at cs.wm.edu> wrote:
> You mean PETSc has no option to only output non-zero values with the
> format (row, column, value)?
>
> Khan, Irfan wrote:
> > I don't think so. Petsc has its own way to output matrix
> information in binary format that is platform independent.
> > However, I found that after loading into matlab, you can save or
> output the matrix in a format that you want.
> >
> > Irfan
> >
> > ----- Original Message -----
> > From: "Yixun Liu" <enjoywm at cs.wm.edu>
> > To: "PETSc users list" <petsc-users at mcs.anl.gov>
> > Sent: Tuesday, February 24, 2009 3:39:51 PM GMT -05:00 US/Canada
> Eastern
> > Subject: Re: output to matlab readable format
> >
> > Thanks!
> >
> > Can I save matrix into (row, column, value) format?
> >
> >
> > Khan, Irfan wrote:
> >
> >> You will need to open a binary file to output the data. Try the
> following.
> >>
> >>
> >> PetscViewer viewer;
> >> ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,
> "matrix", FILE_MODE_WRITE, &viewer);
> >> ierr = MatView(Amat,viewer);
> >> PetscViewerDestroy(viewer);
> >>
> >> In order to load the file into matlab do the following
> >>
> >> % $PETSC_DIR/bin/matlab/PetscBinaryRead("<path_to_file>")
> >>
> >> Irfan
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Hi,
> >> I use the following code to output matrix into file which can be
> read by
> >> matlab,
> >>
> >> PetscViewer aviewer;
> >> PetscViewerCreate(PETSC_COMM_WORLD, &aviewer);
> >> PetscViewerSetType(aviewer, PETSC_VIEWER_ASCII);
> >> //
> PetscObjectSetName((PetscObject)sparseMechanicalStiffnessMatrix,
> >> aname);
> >> PetscViewerSetFormat(aviewer, PETSC_VIEWER_ASCII_MATLAB);
> >> PetscViewerFileSetName(aviewer, aname);
> >> MatView(sparseMechanicalStiffnessMatrix, aviewer);
> >> PetscViewerDestroy(aviewer);
> >>
> >>
> >>
> >> The error is ASCII format file doesn't allow the matrix exceeds 512
> >> rows. So I change PETSC_VIEWER_ASCII to PETSC_VIEWER_BINARY, but
> it seem
> >> that PETSc outputs to screen.
> >>
> >> Thanks.
> >>
> >>
>
>
>
>
> --
> 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
More information about the petsc-users
mailing list