[petsc-users] Getting access to matrix rows without and setting values simultaneously

Alexander Grayver agrayver at gfz-potsdam.de
Thu Jun 16 05:59:24 CDT 2011


Hello!

Sorry for weird subject. The problem is very simple actually. I have big 
distributed dense matrix and I want to change the element of this matrix 
without copying whole matrix.
If I do it this way:

   call MatGetOwnershipRange(A,istart,iend,ierr);CHKERRQ(ierr)
   do i=istart,iend-1
     ! get one row from A
     rowidx(1) = i
     call MatGetRow(A,i,nvals,cols,vals,ierr);CHKERRQ(ierr);

     ! transform all elements in the row
     do j=1,nvals
        transformedvals(j) = func(vals(j))
     enddo

     ! store transformed elements
     call 
MatSetValues(A,1,rowidx,nvals,cols,transformedvals,INSERT_VALUES,ierr);CHKERRQ(ierr);
     call MatRestoreRow(A,i,nvals,cols,vals,ierr);CHKERRQ(ierr);
   enddo

It tells me that I can't use MatGetRow/MatRestoreRow and MatSetValues at 
the same time. So, what would be the better way of doing this?
Maybe MatGetArrayF90? I would like to try it but don't find the 
description of output element arrays.

Regards,
Alexander


More information about the petsc-users mailing list