On Jul 28, 2011, at 12:44 PM, Adam Byrd wrote:
> Dear All,
>
> 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.
Yes it does keep the same ordering from the original matrix.
You need to do the operation in two steps.
Step 1 use MatGetSubMatrices() or MatGetSubMatrix() to get onto each MPI
process the rows/columns that it will need.
Step 2 go through the (now local) part of the matrix and get the values you
want out and put them where you want using the ordering that you want.
Barry
> Essentially, I'm trying to do this:
>
> myArray[n][m] = myPetscMat[i][j]
>
> This is the code I'm rewriting to work collectively on a parallel matrix:
>
> for(int i=0; i<4; i++)
> {
> ierr = MatGetRow(inverseHamiltonian, isl[i]-1, &nonZeros, PETSC_NULL,
> &rowValues);CHKERRQ(ierr);
> for(int j=0; j<4; j++)
> {
> gaml[i][j] = rowValues[isr[j]-1];
> } //endfor
> ierr = MatRestoreRow(inverseHamiltonian, isl[i]-1, &nonZeros,
> PETSC_NULL, &rowValues);CHKERRQ(ierr);
> } //endfor
>
> for(int j=0; j<4; j++)
> {
> ierr = MatGetRow(inverseHamiltonian, isr[j]-1, &nonZeros, PETSC_NULL,
> &rowValues);CHKERRQ(ierr);
> for(int i=0; i<4; i++)
> {
> gamrr[i][j] = conj(rowValues[isl[i]-1]);
> } //endfor
> ierr = MatRestoreRow(inverseHamiltonian, isr[j]-1, &nonZeros,
> PETSC_NULL, &rowValues);CHKERRQ(ierr);
> } //endfor
>
> where isr[] and isl[] contain arbitrary, unsorted indices.
>
> Thanks.