<div dir="ltr"><div>I did not completely understand the suggestion the first time. My bad.<br><br>A.createNest([[mA11,mA12,mA21,mA22]]) works.<br><br>For ,my specific situation,<br>A.createNest([[mA11,mA12],[mA21,mA22]]) works.<br>
<br></div><div>Thanks<br></div><div><br></div>Amit<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 4, 2014 at 12:48 PM, Jed Brown <span dir="ltr"><<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">Amit Itagi <<a href="mailto:gcfrai@gmail.com">gcfrai@gmail.com</a>> writes:<br>
<br>
> I tried the equivalent version with petsc in C++:<br>
><br>
> Mat subA[4];<br>
> Mat A;<br>
> ...<br>
> MatCreateNest(comm,2,NULL,2,NULL,subA,&A);<br>
><br>
> I did not face any issues. I am trying to map it to petsc4py.<br>
<br>
</div>You should take Matt's suggestion.<br>
<br>
Sometimes it is best to look at the source. Lisandro his limited time<br>
to work on petsc4py, and he spends it ensuring that everything works<br>
correctly rather than carefully documenting the interface quirks.<br>
Unfortunately, this means it can be tricky to guess how an interface<br>
should be used. It will probably stay this way until either<br>
cross-language documentation becomes more automated or someone finds<br>
enough time to spend on petsc4py documentation.<br>
<br>
def createNest(self, mats, isrows=None, iscols=None, comm=None):<br>
mats = [list(mat) for mat in mats]<br>
if isrows:<br>
isrows = list(isrows)<br>
assert len(isrows) == len(mats)<br>
else:<br>
isrows = None<br>
if iscols:<br>
iscols = list(iscols)<br>
assert len(iscols) == len(mats[0])<br>
else:<br>
iscols = None<br>
cdef MPI_Comm ccomm = def_Comm(comm, PETSC_COMM_DEFAULT)<br>
cdef Py_ssize_t i, mr = len(mats)<br>
cdef Py_ssize_t j, mc = len(mats[0])<br>
cdef PetscInt nr = <PetscInt>mr<br>
cdef PetscInt nc = <PetscInt>mc<br>
cdef PetscMat *cmats = NULL<br>
cdef PetscIS *cisrows = NULL<br>
cdef PetscIS *ciscols = NULL<br>
cdef object tmp1, tmp2, tmp3<br>
tmp1 = oarray_p(empty_p(nr*nc), NULL, <void**>&cmats)<br>
for i from 0 <= i < mr:<br>
for j from 0 <= j < mc:<br>
cmats[i*mc+j] = (<Mat?>mats[i][j]).mat<br>
if isrows is not None:<br>
tmp2 = oarray_p(empty_p(nr), NULL, <void**>&cisrows)<br>
for i from 0 <= i < mr: cisrows[i] = (<IS?>isrows[i]).iset<br>
if iscols is not None:<br>
tmp3 = oarray_p(empty_p(nc), NULL, <void**>&ciscols)<br>
for j from 0 <= j < mc: ciscols[j] = (<IS?>iscols[j]).iset<br>
cdef PetscMat newmat = NULL<br>
CHKERR( MatCreateNest(ccomm, nr, cisrows, nc, ciscols, cmats, &newmat) )<br>
PetscCLEAR(self.obj); self.mat = newmat<br>
return self<br>
</blockquote></div><br></div>