[petsc-users] Scatter scipy Sparse matrix to petsc local processor

Yongxiang Wu yongxiang27 at gmail.com
Fri Apr 6 07:44:50 CDT 2018


Hello, everyone,

I already have a scipy sparse square matrix L0 . Since my problem is large,
parallel run is preferred. My Question is, how can I scatter my L0 to each
of the processors? In the following code, I can get the indices of the
localized part of the matrix. In the tutorial, the matrix element are
directly assign with value, but in my case, the matrix are so large, assign
each element in loop (commented code) is not efficient. So if any function
would do the mpi scatter work?

With regards and Thanks.

    import sys, slepc4py
    slepc4py.init(sys.argv)
    from petsc4py import PETSc
    from slepc4py import SLEPc

    opts = PETSc.Options()
    opts.setValue('-st_pc_factor_mat_solver_package','mumps')

    A = PETSc.Mat().createAIJ(size=L0.shape,comm=PETSc.COMM_WORLD)
    A.setUp()

    Istart, Iend = A.getOwnershipRange()#    for I in
range(Istart,Iend):#        for J in range(0,L0.shape[0]):#
A[I,J] = L0[I,J]

The flowing code, would make the assignment from the scipy sparse matrix L0 to
PETSc matrix A. But this would only work for one process.

    A = PETSc.Mat().createAIJ(size=L0.shape,
                                   csr=(L0.indptr, L0.indices,
                                        L0.data), comm=PETSc.COMM_WORLD)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180406/e5d800e9/attachment.html>


More information about the petsc-users mailing list