[petsc-users] Mat.createNest in petsc4py

Amit Itagi gcfrai at gmail.com
Fri Apr 4 12:52:47 CDT 2014


I did not completely understand the suggestion the first time. My bad.

A.createNest([[mA11,mA12,mA21,mA22]]) works.

For ,my specific situation,
A.createNest([[mA11,mA12],[mA21,mA22]]) works.

Thanks

Amit


On Fri, Apr 4, 2014 at 12:48 PM, Jed Brown <jed at jedbrown.org> wrote:

> Amit Itagi <gcfrai at gmail.com> writes:
>
> > I tried the equivalent version with petsc in C++:
> >
> >  Mat subA[4];
> >  Mat A;
> >   ...
> >  MatCreateNest(comm,2,NULL,2,NULL,subA,&A);
> >
> > I did not face any issues. I am trying to map it to petsc4py.
>
> You should take Matt's suggestion.
>
> Sometimes it is best to look at the source.  Lisandro his limited time
> to work on petsc4py, and he spends it ensuring that everything works
> correctly rather than carefully documenting the interface quirks.
> Unfortunately, this means it can be tricky to guess how an interface
> should be used.  It will probably stay this way until either
> cross-language documentation becomes more automated or someone finds
> enough time to spend on petsc4py documentation.
>
>     def createNest(self, mats, isrows=None, iscols=None, comm=None):
>         mats = [list(mat) for mat in mats]
>         if isrows:
>             isrows = list(isrows)
>             assert len(isrows) == len(mats)
>         else:
>             isrows = None
>         if iscols:
>             iscols = list(iscols)
>             assert len(iscols) == len(mats[0])
>         else:
>             iscols = None
>         cdef MPI_Comm ccomm = def_Comm(comm, PETSC_COMM_DEFAULT)
>         cdef Py_ssize_t i, mr = len(mats)
>         cdef Py_ssize_t j, mc = len(mats[0])
>         cdef PetscInt nr = <PetscInt>mr
>         cdef PetscInt nc = <PetscInt>mc
>         cdef PetscMat *cmats   = NULL
>         cdef PetscIS  *cisrows = NULL
>         cdef PetscIS  *ciscols = NULL
>         cdef object tmp1, tmp2, tmp3
>         tmp1 = oarray_p(empty_p(nr*nc), NULL, <void**>&cmats)
>         for i from 0 <= i < mr:
>             for j from 0 <= j < mc:
>                 cmats[i*mc+j] = (<Mat?>mats[i][j]).mat
>         if isrows is not None:
>             tmp2 = oarray_p(empty_p(nr), NULL, <void**>&cisrows)
>             for i from 0 <= i < mr: cisrows[i] = (<IS?>isrows[i]).iset
>         if iscols is not None:
>             tmp3 = oarray_p(empty_p(nc), NULL, <void**>&ciscols)
>             for j from 0 <= j < mc: ciscols[j] = (<IS?>iscols[j]).iset
>         cdef PetscMat newmat = NULL
>         CHKERR( MatCreateNest(ccomm, nr, cisrows, nc, ciscols, cmats,
> &newmat) )
>         PetscCLEAR(self.obj); self.mat = newmat
>         return self
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140404/fd7fdd8a/attachment.html>


More information about the petsc-users mailing list