[petsc-users] MatGetRow for global rows of a parallel matrix
Matthew Knepley
knepley at gmail.com
Wed Jun 10 10:11:01 CDT 2020
On Wed, Jun 10, 2020 at 10:09 AM Eda Oktay <eda.oktay at metu.edu.tr> wrote:
> Dear Matt,
>
> I have one last question I believe. Up to creating a dense matrix I
> did what you've suggested. Thank you so much for that.
>
> I created a new dense matrix. Now, how should I wrap each vector in a
> MatDense again? I mean, what is wrapping vectors in a matrix? To put
> each of them again as rows?
>
I thought you need a dense matrix for something, since you started with
one. If you
do not, just do VecGetArray() on the vector from CreateToAll and use the
values.
Thanks,
Matt
> Thanks!
>
> Eda
>
> Matthew Knepley <knepley at gmail.com>, 10 Haz 2020 Çar, 16:16 tarihinde
> şunu yazdı:
> >
> > On Wed, Jun 10, 2020 at 9:08 AM Eda Oktay <eda.oktay at metu.edu.tr> wrote:
> >>
> >> Dear Matt,
> >>
> >> Matthew Knepley <knepley at gmail.com>, 10 Haz 2020 Çar, 16:03 tarihinde
> >> şunu yazdı:
> >> >
> >> > On Wed, Jun 10, 2020 at 8:56 AM Eda Oktay <eda.oktay at metu.edu.tr>
> wrote:
> >> >>
> >> >> Hi all,
> >> >>
> >> >> I am trying to get all the rows of a parallel matrix as individual
> >> >> vectors. For instance, if I have 72*4 matrix, I want to get 72
> >> >> different vectors having size 4.
> >> >>
> >> >> As far as I understood, MatGetRow is only for local rows, so
> >> >> MatGetOwnershipRange is used, however, when I tried this one, I
> >> >> couldn't get the whole and desired row vectors.
> >> >>
> >> >> In MatGetRow explanation, it is written that I should use
> >> >> MatCreateSubMatrices first, then use MatGetRow. But I couldn't
> >> >> understand to which extent I should create submatrices. I just need
> to
> >> >> have all 72 rows as 72 different vectors each having 4 elements.
> >> >
> >> >
> >> > 1) For sparse matrices, the storage is always divided by row, so that
> values can only be retrieved for local rows with MatGetRow()
> >> >
> >> > 2) Is this matrix sparse? It sounds like it is dense.
> >>
> >> Matrix is dense.
> >>
> >> >
> >> > 3) Are you asking to get all matrix values on all processes? If so, I
> think the easiest thing to do is first wrap a Vec around the
> >> > values, then use VecScatterToAll(), then wrap each one in a
> MatDense again.
> >>
> >> Yes, I want all row vectors on all processes. In a dense matrix,
> >> should I still wrap a Vec around the values? I know I should use
> >> scatter but I couldn't even wrap a Vec around them.
> >
> >
> > I would do
> >
> > MatGetSize(&N);
> > MatGetLocalSize(&m);
> >
> https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatDenseGetArray.html
> > <create vector of local size m*N>
> >
> https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecPlaceArray.html
> >
> https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecScatterCreateToAll.html
> > <do scatter>
> >
> https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecResetArray.html#VecResetArray
> >
> https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateDense.html
> > <use it>
> > <destroy matrix>
> > <destroy vector from CreateToAll>
> >
> > Thanks,
> >
> > Matt
> >
> >>
> >> Thanks so much!
> >>
> >> Eda
> >>
> >> >
> >> > Thanks,
> >> >
> >> > Matt
> >> >
> >> >>
> >> >> Thanks!
> >> >>
> >> >> Eda
> >> >
> >> >
> >> >
> >> > --
> >> > What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> >> > -- Norbert Wiener
> >> >
> >> > https://www.cse.buffalo.edu/~knepley/
> >
> >
> >
> > --
> > What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> > -- Norbert Wiener
> >
> > https://www.cse.buffalo.edu/~knepley/
>
--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200610/1187c2b3/attachment-0001.html>
More information about the petsc-users
mailing list