[petsc-users] Finding nonzero indices

Dave May dave.mayhem23 at gmail.com
Tue Feb 26 02:01:50 CST 2019


On Tue, 26 Feb 2019 at 08:50, Eda Oktay via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> Okay, but here is another silly question:
>
> From MatGetRow(), I get number of nonzeros in row, column indices and
> values right?
>

Yes

Also, PetscBinaryWrite() needs a buffer p and the number of items to write
> n.
>
> I need both row,column indices and values.
>

Row index was proved to MatGetRow as an input arg - MatGetRow returns the
rest of what you need.


So, what should I write into PetscBinaryWrite?
>

That's up to you. You are in control of the format of your binary file.


Does this for loop give me these 3 arrays (arrays consist of row
> indices,column indices and values)?
>

Yes but you don't have an array for row indices - you only have a single
value. If you use Matt's loop you would be writing the matrix row by row to
your binary file.



> Eda
>
> Matthew Knepley <knepley at gmail.com>, 25 Şub 2019 Pzt, 18:37 tarihinde
> şunu yazdı:
>
>> On Mon, Feb 25, 2019 at 10:20 AM Eda Oktay <eda.oktay at metu.edu.tr> wrote:
>>
>>> Thank you for your answer Matt, but I have some questions about
>>>> PetscBinaryWrite() since I am a new user.
>>>>
>>>> Since I am going to use this function, I guess I have to open a new
>>>> binary file with PetscViewerBinaryOpen
>>>> <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Viewer/PetscViewerBinaryOpen.html#PetscViewerBinaryOpen>
>>>>  and  PetscViewerBinaryGetDescriptor
>>>> <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Viewer/PetscViewerBinaryGetDescriptor.html#PetscViewerBinaryGetDescriptor>,
>>>> and destroy viewer by  PetscViewerDestroy
>>>> <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Viewer/PetscViewerDestroy.html#PetscViewerDestroy>.
>>>> Do I write these functions into for loop or not?
>>>>
>>>
>> No, they go outside.
>>
>>   Thanks,
>>
>>     Matt
>>
>>
>>> Eda
>>>>
>>>> Matthew Knepley <knepley at gmail.com>, 25 Şub 2019 Pzt, 17:31 tarihinde
>>>> şunu yazdı:
>>>>
>>>>> On Mon, Feb 25, 2019 at 5:25 AM Eda Oktay via petsc-users <
>>>>> petsc-users at mcs.anl.gov> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I am trying to find the indices (both row and column separately) of
>>>>>> nonzero entries of a sparse matrix in Petsc Binary Format. I found
>>>>>> MatGetSeqNonzeroStructure but it gives me a struct and I don't know whether
>>>>>> this is what I want or not.
>>>>>>
>>>>>
>>>>> I would not do it that way, since it is fragile. I would write a loop
>>>>> like this:
>>>>>
>>>>> MAtGetOwnershipRange();
>>>>> for (row = rStart; row < rEnd; ++row) {
>>>>>   MatGetRow()
>>>>>   PetscBinaryWrite()
>>>>>   MatRestoreRow()
>>>>> }
>>>>>
>>>>> This will work for any matrix.
>>>>>
>>>>>     Matt
>>>>>
>>>>>
>>>>>> Best regards,
>>>>>>
>>>>>> 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/
>>>>> <http://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/20190226/03a6946a/attachment.html>


More information about the petsc-users mailing list