[petsc-users] (no subject)
Barry Smith
bsmith at mcs.anl.gov
Thu Sep 15 21:32:53 CDT 2016
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.
Barry
> On Sep 15, 2016, at 9:21 PM, Ji Zhang <gotofd at gmail.com> wrote:
>
> I'm so apologize for the ambiguity. Let me clarify it.
>
> 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,
>
> [ m11 m12 m13 ]
> M = | m21 m22 m23 | ,
> [ m31 m32 m33 ]
>
> 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.
>
> import numpy as np
> from petsc4py import PETSc
>
> mSizes = (5, 8, 6)
> mij = []
>
> # create sub-matrices mij
> for i in range(len(mSizes)):
> for j in range(len(mSizes)):
> temp_m = PETSc.Mat().create(comm=PETSc.COMM_WORLD)
> temp_m.setSizes(((None, mSizes[i]), (None, mSizes[j])))
> temp_m.setType('mpidense')
> temp_m.setFromOptions()
> temp_m.setUp()
> temp_m[:, :] = np.random.random_sample((mSizes[i], mSizes[j]))
> temp_m.assemble()
> mij.append(temp_m)
>
> # Now we have four sub-matrices. I would like to construct them into a big matrix M.
> M = PETSc.Mat().create(comm=PETSc.COMM_WORLD)
> M.setSizes(((None, np.sum(mSizes)), (None, np.sum(mSizes))))
> M.setType('mpidense')
> M.setFromOptions()
> M.setUp()
> mLocations = np.insert(np.cumsum(mSizes), 0, 0) # mLocations = [0, mSizes]
> for i in range(len(mSizes)):
> for j in range(len(mSizes)):
> M[mLocations[i]:mLocations[i+1], mLocations[j]:mLocations[j+1]] = mij[i*len(mSizes)+j][:, :]
> M.assemble()
>
> Thanks.
>
>
> 2016-09-16
> Best,
> Regards,
> Zhang Ji
> Beijing Computational Science Research Center
> E-mail: gotofd at gmail.com
>
>
>
>
>
> Wayne
>
> On Thu, Sep 15, 2016 at 8:58 PM, Matthew Knepley <knepley at gmail.com> wrote:
> On Thu, Sep 15, 2016 at 4:23 AM, Ji Zhang <gotofd at gmail.com> wrote:
> Thanks Matt. It works well for signal core. But is there any solution if I need a MPI program?
>
> It unclear what the stuff below would mean in parallel.
>
> If you want to assemble several blocks of a parallel matrix that looks like serial matrices, then use
>
> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetLocalSubMatrix.html
>
> Thanks,
>
> Matt
>
> Thanks.
>
> Wayne
>
> On Tue, Sep 13, 2016 at 9:30 AM, Matthew Knepley <knepley at gmail.com> wrote:
> On Mon, Sep 12, 2016 at 8:24 PM, Ji Zhang <gotofd at gmail.com> wrote:
> Dear all,
>
> I'm using petsc4py and now face some problems.
> I have a number of small petsc dense matrices mij, and I want to construct them to a big matrix M like this:
>
> [ m11 m12 m13 ]
> M = | m21 m22 m23 | ,
> [ m31 m32 m33 ]
> How could I do it effectively?
>
> Now I'm using the code below:
>
> # get indexes of matrix mij
> index1_begin, index1_end = getindex_i( )
> index2_begin, index2_end = getindex_j( )
> M[index1_begin:index1_end, index2_begin:index2_end] = mij[:, :]
> which report such error messages:
>
> petsc4py.PETSc.Error: error code 56
> [0] MatGetValues() line 1818 in /home/zhangji/PycharmProjects/petsc-petsc-31a1859eaff6/src/mat/interface/matrix.c
> [0] MatGetValues_MPIDense() line 154 in /home/zhangji/PycharmProjects/petsc-petsc-31a1859eaff6/src/mat/impls/dense/mpi/mpidense.c
>
> Make M a sequential dense matrix.
>
> Matt
>
> [0] No support for this operation for this object type
> [0] Only local values currently supported
>
> Thanks.
>
>
> 2016-09-13
> Best,
> Regards,
> Zhang Ji
> Beijing Computational Science Research Center
> E-mail: gotofd at gmail.com
>
>
>
>
>
> --
> 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
>
>
>
>
> --
> 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
>
More information about the petsc-users
mailing list