Dear All,<div><br></div><div>I'm attempting to find the most efficient/simple way to collectively retrieve just a handful of values (local and non local) from a parallel matrix. I'm filling two 4x4 arrays with 4 values from 8 different rows of the solution matrix of a previous solve. So far, MatGetSubMatrices looks my only option (MatGetValues and MatGetRow can only get local values), but seems unlikely to be the most efficient way to do this unless I am able to change the row and column ordering when creating the submatrix. It appears to retain the relative ordering of the rows and columns from the original matrix. Essentially, I'm trying to do this:</div>
<div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">myArray[n][m] = myPetscMat[i][j]</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div>
<div><font class="Apple-style-span" face="arial, helvetica, sans-serif">This is the code I'm rewriting to work collectively on a parallel matrix:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div style="font-family: 'courier new', monospace; ">for(int i=0; i<4; i++)</div><div style="font-family: 'courier new', monospace; ">{</div><div style="font-family: 'courier new', monospace; ">
<span class="Apple-tab-span" style="white-space:pre">        </span>ierr = MatGetRow(inverseHamiltonian, isl[i]-1, &nonZeros, PETSC_NULL, &rowValues);CHKERRQ(ierr);</div><div style="font-family: 'courier new', monospace; ">
<span class="Apple-tab-span" style="white-space:pre">        </span>for(int j=0; j<4; j++)</div><div style="font-family: 'courier new', monospace; "><span class="Apple-tab-span" style="white-space:pre">        </span>{</div>
<div style="font-family: 'courier new', monospace; "><span class="Apple-tab-span" style="white-space:pre">                </span>gaml[i][j] = rowValues[isr[j]-1];</div><div style="font-family: 'courier new', monospace; ">
<span class="Apple-tab-span" style="white-space:pre">        </span>} //endfor</div><div style="font-family: 'courier new', monospace; "><span class="Apple-tab-span" style="white-space:pre">        </span>ierr = MatRestoreRow(inverseHamiltonian, isl[i]-1, &nonZeros, PETSC_NULL, &rowValues);CHKERRQ(ierr);</div>
<div style="font-family: 'courier new', monospace; ">} //endfor</div><div style="font-family: 'courier new', monospace; "><span class="Apple-tab-span" style="white-space:pre">        </span></div><div style="font-family: 'courier new', monospace; ">
for(int j=0; j<4; j++)</div><div style="font-family: 'courier new', monospace; ">{</div><div style="font-family: 'courier new', monospace; "><span class="Apple-tab-span" style="white-space:pre">        </span>ierr = MatGetRow(inverseHamiltonian, isr[j]-1, &nonZeros, PETSC_NULL, &rowValues);CHKERRQ(ierr);</div>
<div style="font-family: 'courier new', monospace; "><span class="Apple-tab-span" style="white-space:pre">        </span>for(int i=0; i<4; i++)</div><div style="font-family: 'courier new', monospace; "><span class="Apple-tab-span" style="white-space:pre">        </span>{</div>
<div style="font-family: 'courier new', monospace; "><span class="Apple-tab-span" style="white-space:pre">                </span>gamrr[i][j] = conj(rowValues[isl[i]-1]);</div><div style="font-family: 'courier new', monospace; ">
<span class="Apple-tab-span" style="white-space:pre">        </span>} //endfor</div><div style="font-family: 'courier new', monospace; "><span class="Apple-tab-span" style="white-space:pre">        </span>ierr = MatRestoreRow(inverseHamiltonian, isr[j]-1, &nonZeros, PETSC_NULL, &rowValues);CHKERRQ(ierr);</div>
<div style="font-family: 'courier new', monospace; ">} //endfor</div><div style="font-family: 'courier new', monospace; "><br></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">where isr[] and isl[] contain arbitrary, unsorted indices.</font></div>
<div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">Thanks.</font></div><div><div><div><div><div><div><div><div>
</div></div></div></div></div></div></div></div>