[petsc-users] MatGetRow and MatSetValues

Jed Brown jedbrown at mcs.anl.gov
Tue Sep 10 20:02:56 CDT 2013


"Jin, Shuangshuang" <Shuangshuang.Jin at pnnl.gov> writes:

> Hello, PETSc developers, I have a question regarding the usage of
> MatGetRow and MatSetValues.
>
> As shown in the piece of code below. I have a matrix A with n rows and
> N_Steps columns, for each time step I_Steps, I want to set A[x,
> I_Steps+1] = A[x, I_Steps] + someComputedValue;
>
> As I understand, in order to read A[x, I_Steps], I have to get the x's
> rows values in A by MatGetRow; In order to set the A[x, I_Steps+1], I
> have to use the MatSetValues.  And these operations require the
> MatAssemblyBegin and MatAssemblyEnd as well.

Yes.

> The problem is when I run the code, it only works when the number of
> processors equal to 1 or n. Otherwise, it's hanging there forever.
>
> I feel like the MatAssemblyBegin and MatAssemblyEnd may be the source
> of the problem.

MatAssemblyBegin and MatAssemblyEnd are collective, but you are not
calling them collectively when the process count is not 1 or evenly
dividing the problem size.

You can get all the values you need in one shot, then set all the values
with MatSetValues, then call assembly once.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130910/7706d15a/attachment-0001.pgp>


More information about the petsc-users mailing list