[petsc-users] Printing parallel matrix

Smith, Barry F. bsmith at mcs.anl.gov
Thu Jan 24 21:58:08 CST 2019


  Is it a very large matrix? The ASCII output is intended for only smallish matrices and may take a lot of time for very large matrices. For large matrices we recommend the binary format which is much faster for large matrices and can handle tens of millions of rows. You can read it into Python or Matlab with utilities we provide.

    Barry


> On Jan 23, 2019, at 9:40 AM, Jed Brown via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> 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