[petsc-users] MatGetRow and MatSetValues
Jin, Shuangshuang
Shuangshuang.Jin at pnnl.gov
Tue Sep 10 23:32:19 CDT 2013
Jed, thank you very much. The way you suggested works!
Thanks,
Shuangshuang
Sent from my iPhone
On Sep 10, 2013, at 18:03, "Jed Brown" <jedbrown at mcs.anl.gov> wrote:
> "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.
More information about the petsc-users
mailing list