On Thu, Jul 10, 2025 at 11:29 AM Arun Soman Pillai - STFC UKRI via petsc-users <petsc-users@mcs.anl.gov> wrote:
> Hi, > I am trying to view a matrix object when running a job in parallel. The > application is BOUT++ > (https://urldefense.us/v3/__https://boutproject.github.io/__;!!G_uCfscf7eWS!ZLeEFXZF4ASJ2hjoTAuK-DQjJkNz_wPtN8mH3P557R1p2cltUNodOb0wrXsWAcQlamre0C1SJy4cn2cXZDeX$ > > <https://urldefense.us/v3/__https://boutproject.github.io/__;!!G_uCfscf7eWS!Z-f_HrmUaFAwAK4e2pBspL2oRFtfq9O3GtRCoS_Nb1e9y5j2Vjq6THJTnoot7XiMeRAxlNhskW0QrMV7x_v_VsBXVAsGHRrIifxc$>) > which uses petsc as solver. > While the option -mat_view gives a jumbled output on STDOUT from across > the processors, > This means that something is terribly wrong. I suspect that you are not actually running in parallel, but rather launching independent jobs. That can happen when mpiexec does not match the MPI library that you linked with. Thanks, Matt > redirecting output to a specific file results in race condition. The only > option that works for me is *-mat_view binary* with *-viewer_binary_filename > <name>**. *I am processing this binary file with petsc4py as follows: > > from petsc4py import PETSc > > import numpy as np > > import matplotlib.pyplot as plt > > import glob > > > > def read_binary(filename): > > viewer = PETSc.Viewer().createMPIIO(filename, "r", > comm=PETSc.COMM_WORLD) > > A = PETSc.Mat().load(viewer) > > A.assemble() > > print("Matrix type:", A.getType()) > > print("Matrix size:", A.getSize()) > > info = A.getInfo() > > print("Number of nonzeros:", info['nz_used']) > > print("Nonzeros allocated:", info['nz_allocated']) > > m, n = A.getSize() > > dense_mat = np.zeros((m, n), dtype=np.float64) > > for i in range(m): > > cols, vals = A.getRow(i) > > dense_mat[i, cols] = vals > > > > rstart, rend = A.getOwnershipRange() > > rows, cols = [], [] > > for i in range(rstart, rend): > > cols_i, _ = A.getRow(i) > > rows.extend([i] * len(cols_i)) > > cols.extend(cols_i) > > > > rows = np.array(rows) > > cols = np.array(cols) > > > > return dense_mat, rows, cols > > > > A, rows, cols = read_binary(“matrix”) > > > > This yields accurate number of non-zeros and matrix sparsity. However, the > dense matrix turns out to be a null matrix. I wonder what is going wrong > here. > > > > Thank you, best regards > > Arun Pillai > -- 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 https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZLeEFXZF4ASJ2hjoTAuK-DQjJkNz_wPtN8mH3P557R1p2cltUNodOb0wrXsWAcQlamre0C1SJy4cn2k7zbgZ$ <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZLeEFXZF4ASJ2hjoTAuK-DQjJkNz_wPtN8mH3P557R1p2cltUNodOb0wrXsWAcQlamre0C1SJy4cn5XgDHit$ >