<div dir="ltr"><p style="margin:0px;padding:0px;word-wrap:break-word;color:rgb(23,43,77);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:-0.07px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">Hello, everyone,</p><p style="margin:0px;padding:0px;word-wrap:break-word;color:rgb(23,43,77);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:-0.07px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">I already have a scipy sparse square matrix<span> </span><code style="font-family:SFMono-Medium,"SF Mono","Segoe UI Mono","Roboto Mono","Ubuntu Mono",Menlo,Courier,monospace;font-size:12px;line-height:1.4;padding:1px 3px;border:0px;border-radius:3px;background:rgb(244,245,247);box-sizing:border-box;display:inline-block;max-width:100%;overflow-x:auto;vertical-align:bottom;white-space:nowrap">L0</code><span> </span>. Since my problem is large, parallel run is preferred. My Question is, how can I scatter my<span> </span><code style="font-family:SFMono-Medium,"SF Mono","Segoe UI Mono","Roboto Mono","Ubuntu Mono",Menlo,Courier,monospace;font-size:12px;line-height:1.4;padding:1px 3px;border:0px;border-radius:3px;background:rgb(244,245,247);box-sizing:border-box;display:inline-block;max-width:100%;overflow-x:auto;vertical-align:bottom;white-space:nowrap">L0</code><span> </span>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? </p><p style="margin:0px;padding:0px;word-wrap:break-word;color:rgb(23,43,77);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:-0.07px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">With regards and <span style="letter-spacing:-0.07px">Thanks.</span></p><div class="gmail-codehilite gmail-language-python" style="margin:10px 0px 0px;padding:0px;color:rgb(23,43,77);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:-0.07px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><pre style="margin:0px;padding:5px 10px;font-family:SFMono-Medium,"SF Mono","Segoe UI Mono","Roboto Mono","Ubuntu Mono",Menlo,Courier,monospace;font-size:12px;line-height:1.4;background:rgb(244,245,247);border:0px;border-radius:3px;overflow-x:auto;word-wrap:normal;letter-spacing:0px"><span></span> <span class="gmail-kn" style="font-weight:700">import</span> <span class="gmail-nn" style="color:rgb(85,85,85)">sys</span><span class="gmail-o" style="font-weight:700">,</span> <span class="gmail-nn" style="color:rgb(85,85,85)">slepc4py</span>
<span class="gmail-n">slepc4py</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">init</span><span class="gmail-p">(</span><span class="gmail-n">sys</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">argv</span><span class="gmail-p">)</span>
<span class="gmail-kn" style="font-weight:700">from</span> <span class="gmail-nn" style="color:rgb(85,85,85)">petsc4py</span> <span class="gmail-kn" style="font-weight:700">import</span> <span class="gmail-n">PETSc</span>
<span class="gmail-kn" style="font-weight:700">from</span> <span class="gmail-nn" style="color:rgb(85,85,85)">slepc4py</span> <span class="gmail-kn" style="font-weight:700">import</span> <span class="gmail-n">SLEPc</span>
<span class="gmail-n">opts</span> <span class="gmail-o" style="font-weight:700">=</span> <span class="gmail-n">PETSc</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">Options</span><span class="gmail-p">()</span>
<span class="gmail-n">opts</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">setValue</span><span class="gmail-p">(</span><span class="gmail-s1" style="color:rgb(187,136,68)">'-st_pc_factor_mat_solver_package'</span><span class="gmail-p">,</span><span class="gmail-s1" style="color:rgb(187,136,68)">'mumps'</span><span class="gmail-p">)</span>
<span class="gmail-n">A</span> <span class="gmail-o" style="font-weight:700">=</span> <span class="gmail-n">PETSc</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">Mat</span><span class="gmail-p">()</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">createAIJ</span><span class="gmail-p">(</span><span class="gmail-n">size</span><span class="gmail-o" style="font-weight:700">=</span><span class="gmail-n">L0</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">shape</span><span class="gmail-p">,</span><span class="gmail-n">comm</span><span class="gmail-o" style="font-weight:700">=</span><span class="gmail-n">PETSc</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">COMM_WORLD</span><span class="gmail-p">)</span>
<span class="gmail-n">A</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">setUp</span><span class="gmail-p">()</span>
<span class="gmail-n">Istart</span><span class="gmail-p">,</span> <span class="gmail-n">Iend</span> <span class="gmail-o" style="font-weight:700">=</span> <span class="gmail-n">A</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">getOwnershipRange</span><span class="gmail-p">()</span>
<span class="gmail-c1" style="font-style:italic;color:rgb(153,153,136)"># for I in range(Istart,Iend):</span>
<span class="gmail-c1" style="font-style:italic;color:rgb(153,153,136)"># for J in range(0,L0.shape[0]):</span>
<span class="gmail-c1" style="font-style:italic;color:rgb(153,153,136)"># A[I,J] = L0[I,J]</span>
</pre></div><p style="margin:12px 0px 0px;padding:0px;word-wrap:break-word;color:rgb(23,43,77);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:-0.07px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">The flowing code, would make the assignment from the scipy sparse matrix<span> </span><code style="font-family:SFMono-Medium,"SF Mono","Segoe UI Mono","Roboto Mono","Ubuntu Mono",Menlo,Courier,monospace;font-size:12px;line-height:1.4;padding:1px 3px;border:0px;border-radius:3px;background:rgb(244,245,247);box-sizing:border-box;display:inline-block;max-width:100%;overflow-x:auto;vertical-align:bottom;white-space:nowrap">L0</code><span> </span>to PETSc matrix A. But this would only work for one process.</p><div class="gmail-codehilite gmail-language-python" style="margin:10px 0px 0px;padding:0px;color:rgb(23,43,77);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:-0.07px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><pre style="margin:0px;padding:5px 10px;font-family:SFMono-Medium,"SF Mono","Segoe UI Mono","Roboto Mono","Ubuntu Mono",Menlo,Courier,monospace;font-size:12px;line-height:1.4;background:rgb(244,245,247);border:0px;border-radius:3px;overflow-x:auto;word-wrap:normal;letter-spacing:0px"><span></span> <span class="gmail-n">A</span> <span class="gmail-o" style="font-weight:700">=</span> <span class="gmail-n">PETSc</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">Mat</span><span class="gmail-p">()</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">createAIJ</span><span class="gmail-p">(</span><span class="gmail-n">size</span><span class="gmail-o" style="font-weight:700">=</span><span class="gmail-n">L0</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">shape</span><span class="gmail-p">,</span>
<span class="gmail-n">csr</span><span class="gmail-o" style="font-weight:700">=</span><span class="gmail-p">(</span><span class="gmail-n">L0</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">indptr</span><span class="gmail-p">,</span> <span class="gmail-n">L0</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">indices</span><span class="gmail-p">,</span>
<span class="gmail-n">L0</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">data</span><span class="gmail-p">),</span> <span class="gmail-n">comm</span><span class="gmail-o" style="font-weight:700">=</span><span class="gmail-n">PETSc</span><span class="gmail-o" style="font-weight:700">.</span><span class="gmail-n">COMM_WORLD</span><span class="gmail-p">)</span></pre></div><br></div>