[petsc-users] MatAYPX for dense and sparse matrices

Matthew Knepley knepley at gmail.com
Mon Mar 21 06:45:25 CDT 2011


On Mon, Mar 21, 2011 at 6:40 AM, Alexander Grayver
<agrayver at gfz-potsdam.de>wrote:

>  On 21.03.2011 12:37, Jed Brown wrote:
>
> On Mon, Mar 21, 2011 at 12:31, Alexander Grayver <agrayver at gfz-potsdam.de>wrote:
>
>> Would I have to rebuild PETSc from scratch to make this wrapper working?
>>
>
>  You would put it in your project and link it with your Fortran code.
>
>
>>
>>
>>  Alternatively, the code for this is really simple, just iterate through
>> the rows of L and insert them into J.
>>
>>  Do you mean using MatGetOwnershipRange+MatGetSubMatrices+MatGetRow?
>>
>
> Just translate the following (taken from MatAXPY_Basic) to Fortran:
>
>    ierr = MatGetSize(X,&m,&n);CHKERRQ(ierr);
>   ierr = MatGetOwnershipRange(X,&start,&end);CHKERRQ(ierr);
>   for (i = start; i < end; i++) {
>     ierr = MatGetRow(X,i,&ncols,&row,&vals);CHKERRQ(ierr);
>     ierr = MatSetValues(Y,1,&i,ncols,row,vals,ADD_VALUES);CHKERRQ(ierr);
>     ierr = MatRestoreRow(X,i,&ncols,&row,&vals);CHKERRQ(ierr);
>   }
>   ierr = MatAssemblyBegin(Y,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
>   ierr = MatAssemblyEnd(Y,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
>
>  Thanks Jed, it looks simple enough for me (PETSc is great).
>
> One more question. I get matrix J out of MatMatMult operation and then I
> have to add L matrix up, wouldn't there be a conflict using
> MatAssemblyBegin/MatAssemblyEnd again? Generally, is it allowed to set new
> values into the matrix after MatAssemblyBegin/MatAssemblyEnd already has
> been done once?
>

No, you can use them. However, if you are adding to existing values on your
process, nothing happens.

   Matt


> Thanks a lot.
>



-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110321/6cea9473/attachment.htm>


More information about the petsc-users mailing list