[petsc-users] Printing parallel matrix
Jed Brown
jed at jedbrown.org
Wed Jan 23 09:40:32 CST 2019
Evan Um via petsc-users <petsc-users at mcs.anl.gov> writes:
> Dear PETSC users,
>
> I try to verify a matrix by printing a PETSC matrix and comparing its
> elements with reference values. Below is my test code.
>
> It works well when a single process is used. The output file is created
> quickly. In contrast, when multiple processes (>2) are used, printing
> matrix is stuck (the parallel matrix is assembled very quickly owing to
> memory preallocation). The output file just prints two lines below. No
> element is printed.
>
> Mat Object: 2 MPI processes
> type: mpiaij
>
> I assume that printing matrix is also designed for a parallel matrix. Does
> this suggest that my parallel matrix includes any errors? Otherwise, does
> this work only for a serial matrix?
>
> Thanks for reading this question.
>
> Regards,
> Evan
>
> MatCreateAIJ(PETSC_COMM_WORLD, m, n, M, N, 0, d_nnz_A, 0, o_nnz_A, &Mat_A);
> MatSetFromOptions(Mat_A);
>
> for (int i=rstart_A[rank]; i<rend_A[rank]; i++) {
> mat_value=val_A[i]+PETSC_i*0.0;
> MatSetValue(Mat_A, i_A[i],j_A[i],mat_value,ADD_VALUES);
> }
>
> MatAssemblyBegin(Mat_A, MAT_FINAL_ASSEMBLY);
> MatAssemblyEnd(Mat_A, MAT_FINAL_ASSEMBLY);
>
> PetscViewer viewer;
> PetscViewerASCIIOpen(PETSC_COMM_WORLD,"Mat_A",&viewer);
> MatView(Mat_A,viewer);
> PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB);
Did you intend to use the MATLAB format? If so, MatView needs to be
called while the format is pushed, so swap the two lines above.
> PetscViewerPopFormat(viewer);
> PetscViewerDestroy(&viewer);
More information about the petsc-users
mailing list