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

Matthew Knepley knepley at gmail.com
Fri Apr 6 08:00:43 CDT 2018


On Fri, Apr 6, 2018 at 8:44 AM, Yongxiang Wu <yongxiang27 at gmail.com> wrote:

> 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?
>

Hi Yongxiang,

It would be really anomalous for what you propose to results in any speedup
at all. If the matrix is large,
it will not fit on one process. Any speedup from using more processes will
be eaten up by the time to
communicate the matrix. I would focus on generating the matrix in parallel.

  Thanks,

     Matt


> 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)
>
>
>


-- 
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://www.cse.buffalo.edu/~knepley/ <http://www.caam.rice.edu/~mk51/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180406/bea2c6cb/attachment.html>


More information about the petsc-users mailing list