<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<font face="Calibri, sans-serif" size="2">
<div>Hello, PETSc developers, I have a question regarding the usage of MatGetRow and MatSetValues. </div>
<div><font face="Times New Roman, serif"> </font></div>
<div>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;</div>
<div><font face="Times New Roman, serif"> </font></div>
<div>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.</div>
<div> </div>
<div>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. </div>
<div><font face="Times New Roman, serif"> </font></div>
<div>I feel like the MatAssemblyBegin and MatAssemblyEnd may be the source of the problem. </div>
<div><font face="Times New Roman, serif"> </font></div>
<div>How to fix the error? Or is there a better way to implement this?</div>
<div><font face="Times New Roman, serif"> </font></div>
<div>Thanks,</div>
<div>Shuangshuang</div>
<div><font face="Times New Roman, serif"> </font></div>
<div><font face="Times New Roman, serif"> </font></div>
<div>Mat A;</div>
<div>ierr = MatGetOwnershipRange(A, &lo, &hi); CHKERRQ(ierr);</div>
<div><font face="Times New Roman, serif"> </font></div>
<div>const PetscScalar *AVals;</div>
<div>for (I_Steps = 0; I_Steps < N_Steps; I_Steps++) {</div>
<div> for (k = lo; k < hi; k++) { </div>
<div style="padding-left: 36pt; "> ierr = MatGetRow(A, k, &ncols, &cols, &AVals); CHKERRQ(ierr);</div>
<div style="padding-left: 36pt; "> val[0] = AVals[cols[I_Steps]] + someComputedValue;</div>
<div style="padding-left: 36pt; "> ierr = MatRestoreRow(A, k, &ncols, &cols, &AVals); CHKERRQ(ierr);</div>
<div style="padding-left: 36pt; "><font face="Times New Roman, serif"> </font></div>
<div style="padding-left: 36pt; "> j = I_Steps+1;</div>
<div style="padding-left: 36pt; "> ierr = MatSetValues(A, 1, &k, 1, &j, val, INSERT_VALUES); CHKERRQ(ierr);</div>
<div style="padding-left: 36pt; "> ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);</div>
<div style="padding-left: 36pt; "> ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);</div>
<div style="padding-left: 36pt; "> MatView(A, PETSC_VIEWER_STDOUT_WORLD);</div>
<div> }</div>
<div>}</div>
<div> </div>
<div><font face="Times New Roman, serif"> </font></div>
<div><font face="Times New Roman, serif"> </font></div>
</font>
</body>
</html>