[petsc-users] MatAYPX for dense and sparse matrices

Jed Brown jed at 59A2.org
Mon Mar 21 06:37:29 CDT 2011


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


More information about the petsc-users mailing list