[petsc-users] Wrong variable name in MatView with PETSC_VIEWER_ASCII_MATLAB

Michael Souza souza.michael at gmail.com
Sat Jan 17 14:29:26 CST 2015


The name of variable created by MatView using PETSC_VIEWER_ASCII_MATLAB is
not the expected one. More clearly, the name of variable is "zzz" no matter
what you set by calling PetscObjectSetName.

The code below reproduces the unexpected behaviour. There, I create a
diagonal MATMPIAIJ matrix and I set its name to "A", but the name of
created variable in MATLAB's script is "zzz".

I also would like to point that there is no need to print the line "zzz =
[m n];" once its value will not be used and it will produce an warning at
Matlab's editor. So I think it could be removed.

Note: This strange behaviour doesn't occur with MATSEQAIJ matrices.

Cheers,
Michael Souza
----------------------------------------------------------
int main(int argc, char **args) {
    PetscErrorCode ierr;
    Mat A;
    PetscInt i, N = 3;

    ierr = PetscInitialize(&argc, &args, (char *) 0, help);CHKERRQ(ierr);

    // matrix creation and setup
    ierr = MatCreate(PETSC_COMM_WORLD, &A);CHKERRQ(ierr);
    ierr = MatSetType(A, MATMPIAIJ);CHKERRQ(ierr);
    ierr = MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, N, N);CHKERRQ(ierr);
    ierr = MatSetUp(A);CHKERRQ(ierr);
    for (i = 0; i < N; i++) {
        ierr = MatSetValue(A, i, i, 1.0, INSERT_VALUES);CHKERRQ(ierr);
    }
    ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
    ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);

    // matlab viewer
    ierr = PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD,
PETSC_VIEWER_ASCII_MATLAB);CHKERRQ(ierr);
    ierr = PetscObjectSetName((PetscObject) A, "A");CHKERRQ(ierr);
    ierr = MatView(A, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);

    // free memory
    ierr = MatDestroy(&A);CHKERRQ(ierr);

    ierr = PetscFinalize();CHKERRQ(ierr);

    return EXIT_SUCCESSSS;
}
----------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150117/2eaf4a94/attachment.html>


More information about the petsc-users mailing list