PETSc matrices and vectors I/O

Consider the following:

from petsc4py import PETSc
from mpi4py import MPI

A = PETSc.Mat().create(MPI.COMM_WORLD)
A.setSizes([3, 3])
A.setFromOptions()
A.setUp()
A.setValuesLocal([0], [2], [3])
A.assemble()

viewer = PETSc.Viewer().createBinary("A.mat", mode=PETSc.Viewer.Mode.WRITE, comm=MPI.COMM_WORLD)

viewer(A)
1 Like