<div dir="ltr"><div class="gmail_extra"><div><div class="gmail_signature">Thanks for your warm help. Could you please show me some necessary functions or a simple demo code? <br></div><div class="gmail_signature"><br><br>Wayne</div></div>
<br><div class="gmail_quote">On Fri, Sep 16, 2016 at 10:32 AM, Barry Smith <span dir="ltr"><<a target="_blank" href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><br>
You should create your small m_ij matrices as just dense two dimensional arrays and then set them into the big M matrix. Do not create the small dense matrices as PETSc matrices.<br>
<span class="gmail-HOEnZb"><font color="#888888"><br>
Barry<br>
</font></span><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
<br>
> On Sep 15, 2016, at 9:21 PM, Ji Zhang <<a href="mailto:gotofd@gmail.com">gotofd@gmail.com</a>> wrote:<br>
><br>
> I'm so apologize for the ambiguity. Let me clarify it.<br>
><br>
> I'm trying to simulation interactions among different bodies. Now I have calculated the interaction between two of them and stored in the sub-matrix m_ij. What I want to do is to consider the whole interaction and construct all sub-matrices m_ij into a big matrix M, just like this, imaging the problem contain 3 bodies,<br>
><br>
> [ m11 m12 m13 ]<br>
> M = | m21 m22 m23 | ,<br>
> [ m31 m32 m33 ]<br>
><br>
> The system is huge that I have to use MPI and a lot of cups. A mcve code is showing below, and I'm using a python wrap of PETSc, however, their grammar is similar.<br>
><br>
> import numpy as np<br>
> from petsc4py import PETSc<br>
><br>
> mSizes = (5, 8, 6)<br>
> mij = []<br>
><br>
> # create sub-matrices mij<br>
> for i in range(len(mSizes)):<br>
> for j in range(len(mSizes)):<br>
> temp_m = PETSc.Mat().create(comm=PETSc.<wbr>COMM_WORLD)<br>
> temp_m.setSizes(((None, mSizes[i]), (None, mSizes[j])))<br>
> temp_m.setType('mpidense')<br>
> temp_m.setFromOptions()<br>
> temp_m.setUp()<br>
> temp_m[:, :] = np.random.random_sample((<wbr>mSizes[i], mSizes[j]))<br>
> temp_m.assemble()<br>
> mij.append(temp_m)<br>
><br>
> # Now we have four sub-matrices. I would like to construct them into a big matrix M.<br>
> M = PETSc.Mat().create(comm=PETSc.<wbr>COMM_WORLD)<br>
> M.setSizes(((None, np.sum(mSizes)), (None, np.sum(mSizes))))<br>
> M.setType('mpidense')<br>
> M.setFromOptions()<br>
> M.setUp()<br>
> mLocations = np.insert(np.cumsum(mSizes), 0, 0) # mLocations = [0, mSizes]<br>
> for i in range(len(mSizes)):<br>
> for j in range(len(mSizes)):<br>
> M[mLocations[i]:mLocations[i+<wbr>1], mLocations[j]:mLocations[j+1]] = mij[i*len(mSizes)+j][:, :]<br>
> M.assemble()<br>
><br>
> Thanks.<br>
><br>
><br>
> 2016-09-16<br>
> Best,<br>
> Regards,<br>
> Zhang Ji<br>
> Beijing Computational Science Research Center<br>
> E-mail: <a href="mailto:gotofd@gmail.com">gotofd@gmail.com</a><br>
><br>
><br>
><br>
><br>
><br>
> Wayne<br>
><br>
> On Thu, Sep 15, 2016 at 8:58 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>
> On Thu, Sep 15, 2016 at 4:23 AM, Ji Zhang <<a href="mailto:gotofd@gmail.com">gotofd@gmail.com</a>> wrote:<br>
> Thanks Matt. It works well for signal core. But is there any solution if I need a MPI program?<br>
><br>
> It unclear what the stuff below would mean in parallel.<br>
><br>
> If you want to assemble several blocks of a parallel matrix that looks like serial matrices, then use<br>
><br>
> <a target="_blank" rel="noreferrer" href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetLocalSubMatrix.html">http://www.mcs.anl.gov/petsc/<wbr>petsc-current/docs/<wbr>manualpages/Mat/<wbr>MatGetLocalSubMatrix.html</a><br>
><br>
> Thanks,<br>
><br>
> Matt<br>
><br>
> Thanks.<br>
><br>
> Wayne<br>
><br>
> On Tue, Sep 13, 2016 at 9:30 AM, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>
> On Mon, Sep 12, 2016 at 8:24 PM, Ji Zhang <<a href="mailto:gotofd@gmail.com">gotofd@gmail.com</a>> wrote:<br>
> Dear all,<br>
><br>
> I'm using petsc4py and now face some problems.<br>
> I have a number of small petsc dense matrices mij, and I want to construct them to a big matrix M like this:<br>
><br>
> [ m11 m12 m13 ]<br>
> M = | m21 m22 m23 | ,<br>
> [ m31 m32 m33 ]<br>
> How could I do it effectively?<br>
><br>
> Now I'm using the code below:<br>
><br>
> # get indexes of matrix mij<br>
> index1_begin, index1_end = getindex_i( )<br>
> index2_begin, index2_end = getindex_j( )<br>
> M[index1_begin:index1_end, index2_begin:index2_end] = mij[:, :]<br>
> which report such error messages:<br>
><br>
> petsc4py.PETSc.Error: error code 56<br>
> [0] MatGetValues() line 1818 in /home/zhangji/PycharmProjects/<wbr>petsc-petsc-31a1859eaff6/src/<wbr>mat/interface/matrix.c<br>
> [0] MatGetValues_MPIDense() line 154 in /home/zhangji/PycharmProjects/<wbr>petsc-petsc-31a1859eaff6/src/<wbr>mat/impls/dense/mpi/mpidense.c<br>
><br>
> Make M a sequential dense matrix.<br>
><br>
> Matt<br>
><br>
> [0] No support for this operation for this object type<br>
> [0] Only local values currently supported<br>
><br>
> Thanks.<br>
><br>
><br>
> 2016-09-13<br>
> Best,<br>
> Regards,<br>
> Zhang Ji<br>
> Beijing Computational Science Research Center<br>
> E-mail: <a href="mailto:gotofd@gmail.com">gotofd@gmail.com</a><br>
><br>
><br>
><br>
><br>
><br>
> --<br>
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
> -- Norbert Wiener<br>
><br>
><br>
><br>
><br>
> --<br>
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
> -- Norbert Wiener<br>
><br>
<br>
</div></div></blockquote></div><br></div></div>