<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Nov 28, 2018 at 12:06 PM Florian Lindner <<a href="mailto:mailinglists@xgm.de">mailinglists@xgm.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey,<br>
<br>
thanks for your quick reply!<br>
<br>
As far as I understand how MatSetLocalToGlobalMapping works, there is no way to create such a mapping that can be used for MatSetValuesLocal?<br>
<br>
What I need is basically<br>
<br>
MatSetValuesLocal row/col argument = 3 / 4 / 6 maps to local row/col 0 / 1 / 2<br></blockquote><div><br></div><div>You are inverting the meaning of MatSetValuesLocal(). It takes in local indices (0, 1, 2) and sets the</div><div>values into a global matrix using global indices (3, 4, 6) which it gets from a compact table.</div><div><br></div><div>It you have global indices (3, 4, 6) use MatSetValues() directly.</div><div><br></div><div>Why are you trying to convert global indices to local indices, which requires a search.</div><div><br></div><div> Thanks,</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">
I seems to me, that if I set an index set with MatSetLocalToGlobalMapping like {3, 4, 6} it does the opposite. i.e. maps local {0, 1, 2] to global {3, 4, 6}<br>
<br>
Therefore I probably need to create my own translation of {3, 4, 6} to {0, 1, 2}<br>
<br>
A first sketch looks like that<br>
<br>
mapping[rank] = {3, 4, 6}<br>
<br>
for (auto i : mapping[rank]) {<br>
for (auto j : mapping[rank]) {<br>
cout << "Setting " << i << ", " << j << endl;<br>
PetscScalar v[] = {i*10.0 + j};<br>
PetscInt rows[] = {i};<br>
PetscInt cols[] = {j};<br>
AOApplicationToPetsc(ao, 1, rows);<br>
AOApplicationToPetsc(ao, 1, cols);<br>
cout << "Really setting " << rows[0] << ", " << cols[0] << endl << endl;<br>
ierr = MatSetValues(matrix, 1, rows, 1, cols, v, INSERT_VALUES); CHKERRQ(ierr);<br>
}<br>
}<br>
<br>
which seems to work so far.<br>
<br>
Any comments from your side are appreciated!<br>
<br>
Of course, I should set as much values as possible using MatSetValues...<br>
<br>
Best,<br>
Florian<br>
<br>
<br>
Am 27.11.18 um 16:33 schrieb Matthew Knepley:<br>
> On Tue, Nov 27, 2018 at 10:17 AM Florian Lindner via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a> <mailto:<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>>> wrote:<br>
> <br>
> Hello,<br>
> <br>
> I have a range of local input data indices that I want to use for row indexing, say { 3, 4, 6}.<br>
> <br>
> For that, I create a matrix with a local number of rows of 3 and map the indices {3, 4, 5} to these rows.<br>
> <br>
> <br>
> It seems like you are trying to create a mapping and its inverse. We do that in <br>
> <br>
> <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/AO/AOCreateMapping.html" rel="noreferrer" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/AO/AOCreateMapping.html</a><br>
> <br>
> Note that this is not really scalable. Usually there is a way to restructure the code to avoid this.<br>
> <br>
> Thanks,<br>
> <br>
> Matt<br>
> <br>
> <br>
> I create an index set:<br>
> <br>
> ISCreateGeneral(comm, myIndizes.size(), myIndizes.data(), PETSC_COPY_VALUES, &ISlocal);<br>
> ISSetPermutation(ISlocal);<br>
> ISInvertPermutation(ISlocal, myIndizes.size(), &ISlocalInv);<br>
> ISAllGather(ISlocalInv, &ISglobal); // Gather the IS from all processors<br>
> ISLocalToGlobalMappingCreateIS(ISglobal, &ISmapping); // Make it a mapping<br>
> <br>
> MatSetLocalToGlobalMapping(matrix, ISmapping, ISmapping); // Set mapping for rows and cols<br>
> <br>
> The InvertPermutation is required because, well, it seems that the direction the mapping stuff works in PETSc.<br>
> <br>
> Now I can use MatSetValues local to set rows {3, 4, 5} and actually set the local rows {1, 2, 3}.<br>
> <br>
> The problem is that the range of data vertices is not always contiguous, i.e. could be {3, 4, 6}. This seems to be not a permutation of PETSc, therefore ISSetPermutation fails and subsequently ISInvertPermutation.<br>
> <br>
> How can I still create such a mapping, so that:<br>
> <br>
> 3 -> 1<br>
> 4 -> 2<br>
> 6 -> 6<br>
> <br>
> row 5 is unassigned and will never be addressed.<br>
> <br>
> Thanks!<br>
> Florian<br>
> <br>
> <br>
> <br>
> <br>
> -- <br>
> 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<br>
> <br>
> <a href="https://www.cse.buffalo.edu/~knepley/" rel="noreferrer" target="_blank">https://www.cse.buffalo.edu/~knepley/</a> <<a href="http://www.cse.buffalo.edu/~knepley/" rel="noreferrer" target="_blank">http://www.cse.buffalo.edu/~knepley/</a>><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>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><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>