[petsc-users] MatAYPX for dense and sparse matrices
Alexander Grayver
agrayver at gfz-potsdam.de
Mon Mar 21 06:40:49 CDT 2011
On 21.03.2011 12:37, Jed Brown wrote:
> On Mon, Mar 21, 2011 at 12:31, Alexander Grayver
> <agrayver at gfz-potsdam.de <mailto: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?
Thanks a lot.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110321/9b87fbfa/attachment-0001.htm>
More information about the petsc-users
mailing list