<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>
<div>Not sure how much overhead it produces but copying the actual values with MatGetRow is not necessary as I only need the col position of the nonzero elements in each row. </div>
<div>Inserting the Matrix back is not so complicated as the submatrix is a continous square matrix from somewhere in the bigger matrix. So I only need the row and column offset.</div>
<div>
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><br/>
<br/>
> On Jan 30, 2018, at 6:53 PM, Marius Buerkle <mbuerkle@web.de> wrote:<br/>
><br/>
> Barry,<br/>
><br/>
> Thanks for you reply. The pulled matrix is symmetric but that's it. At the moment I am doing a copy of the matrix right after MatCreateSubMatrix to keep it's nonzero structure. To insert the matrix which I obtained after the multiplications back into the bigger matrix I use the initially copied Matrix to get the nonzero elements with MatGetRow and as I know the offset of the SubMatrix relative to the elements of the big-one I can use MatSetValues to insert the elements row by row. That kinda works but it is rather inefficient.<br/>
<br/>
How do you know it is inefficient?<br/>
<br/>
Are you doing some kind of search on each element of each row to see if it fits in the original nonzero pattern of the block?<br/>
<br/>
Anything else that is inefficient?<br/>
<br/>
Barry<br/>
<br/>
> Is there anyway to avoid copying the whole submatrix in the beginning, as I don't need the actual values but only the positions of the nonzero elements in one way or the other.<br/>
><br/>
> Marius<br/>
><br/>
><br/>
><br/>
>> Marius,<br/>
>><br/>
>> We don't provide a way to insert a "generic" sparse matrix into a bigger matrices (dense matrices coming from element stiffness matrices yes) so I don't see any simple solution. >Does the submatrix you pull out have any particular structure, what does it represent?<br/>
>><br/>
>> Barry<br/>
><br/>
><br/>
>>><br/>
>>> Hi !<br/>
>>><br/>
>>> I have the followng problem. I create a Submatrix containing a subset of row/columns of the original matrix. After some matrix multiplications the non-zero strucutre of the resulting matrix changed. Now I want to insert this submatix back into the original one keeping only the non-zero entries which are present in the original matrix discarding the others which accumulated due to the matrix multiplications. Is there an easy or also not so easy way to do this ?<br/>
>>><br/>
>>> Best,<br/>
>>> Marius<br/>
><br/>
</div>
</div>
</div>
</div></div></body></html>