<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 20, 2015 at 10:53 AM, Bikash Kanungo <span dir="ltr"><<a href="mailto:bikash@umich.edu" target="_blank">bikash@umich.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi,<br><br></div>I was trying to perform a simple test on MatGetSubMatrices. I have an MPIDENSE matrix X which has been populated and assembled and another matrix XTemp of the same type and size. Since X is MPIDENSE in order to extract a sub-matrix from it, the IS must be sorted. This can be done easily through ISSort. Once the sub-matrix is obtained, I'm trying to set the values in XTemp by using the sorted IS as the global indices and the sub-matrix as the values to be set. Once XTemp is set and assembled, I evaluate XTemp - X and see if the norm of the resultant matrix is zero or not. The norm turned out to be as high as 1.0e6. </div></div></blockquote><div><br></div><div>Make the problem very small (10 rows maybe) and starting printing things out.</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div> <br></div>I'm providing a simplified version of the code that performs the above test. Kindly let me know if I have done any mistake is designing the test.<br><br> <br> //<br> // Given an initialized and assembled MPIDENSE Mat X and <br> // an uninitialized MPIDENSE Mat XTemp of the same size as that of X <br> //<br> IS * ISRowIds, * ISColIds;<br> PetscMalloc(1*sizeof(IS), &ISRowIds);<br> PetscMalloc(1*sizeof(IS), &ISColIds);<br><br> //<br> // globalRowIds and globalColIds are STL vectors containing <br> // the global node ids for which the sub-matrix from X need <br> // to be extracted<br> //<br> const PetscInt * rowIdsPtr = globalRowIds.data();<br> const PetscInt * colIdsPtr = globalColIds.data(); <br><br> ISCreateGeneral(PETSC_COMM_WORLD, globalRowIds.size(), rowIdsPtr, PETSC_COPY_VALUES, &ISRowIds[0]);<br> ISCreateGeneral(PETSC_COMM_WORLD, globalColIds.size(), colIdsPtr, PETSC_COPY_VALUES, &ISColIds[0]); <br> ISSort(ISRowIds[0]);<br> ISSort(ISColIds[0]);<br><br> Mat * subMat;<br> MatGetSubMatrices(X, 1, ISRowIds, ISColIds, MAT_INITIAL_MATRIX, &subMat);<br><br> PetscScalar * subMatValues;<br> MatDenseGetArray(*subMat, &subMatValues);<br> <br> const PetscInt * rowIndicesSorted, * colIndicesSorted;<br> ISGetIndices(ISRowIds[0], &rowIndicesSorted);<br> ISGetIndices(ISColIds[0], &colIndicesSorted); <br><br> MatSetValues(XTemp,<br> globalRowIds.size(),<br> rowIndicesSorted,<br> globalColIds.size(),<br> colIndicesSorted,<br> subMatValues,<br> INSERT_VALUES);<br><br> //<br> // commencing assembly<br> //<br> MatAssemblyBegin(XTemp,<br> MAT_FINAL_ASSEMBLY);<br> <br> //<br> // concluding assembly<br> //<br> MatAssemblyEnd(XTemp,<br> MAT_FINAL_ASSEMBLY);<br><br> MatAXPY(XTemp, -1.0, X, DIFFERENT_NONZERO_PATTERN);<br> double diffNorm;<br> MatNorm(XTemp, NORM_1, &diffNorm);<br><div><br clear="all"><div><div><br><br></div><div>Thanks,<br></div><div>Bikash<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>-- <br><div><div dir="ltr"><div><div><div><div><font color="#666666">Bikash S. Kanungo<br></font></div><font color="#666666">PhD Student<br></font></div><font color="#666666">Computational Materials Physics Group<br></font></div><font color="#666666">Mechanical Engineering <br></font></div><font color="#666666">University of Michigan<br><br></font></div></div>
</div></font></span></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div>