import sys
import time
import petsc4py
petsc4py.init(sys.argv)
from petsc4py import PETSc

MATSIZE = 1e+6
mat = PETSc.Mat().createAIJ((MATSIZE, MATSIZE), comm=PETSc.COMM_SELF)
mat.setPreallocationNNZ(50)
mat.setRandom()
mat.assemble()

x, b = mat.createVecs()
x.setRandom()

time_start = time.time()
for _ in range(100):
    mat.mult(x, b)

if PETSc.COMM_WORLD.rank == 0:
    print(f"{time.time() - time_start:.2f}s")