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" <[email protected]> wrote: > "Jin, Shuangshuang" <[email protected]> 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.
