Scatter scipy Sparse matrix to petsc local processor

Issue #94 closed
Wu created an issue

Hello, 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 processor ? 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? 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)

Comments (3)

  1. Lisandro Dalcin

    I guess you have to learn some MPI and use mpi4py and do the scatter by hand. Ar ask these questions int the petsc-users mailing list, which is a more appropriate place with much more visibility than this issue tracker. This place intend to track actual issues within petsc4py, not general questions and help.

  2. Log in to comment