[petsc-users] Problem in MatSetValues

Eda Oktay eda.oktay at metu.edu.tr
Mon Mar 11 08:07:04 CDT 2019


Dear Matt,

I printed in wrong state, ncols gives right solution.

But I still can't understand the first problem.

Eda

Eda Oktay <eda.oktay at metu.edu.tr>, 11 Mar 2019 Pzt, 16:05 tarihinde şunu
yazdı:

> Dear Matt,
>
> Thank you for answering. First of all, sizeof(vals) returns to number of
> entries, I checked. Secondly, I found a problem:
>
> ncols gives me 6.95328e-310. However, I checked the matrix L, it was
> computed properly.
>
> Why can ncols give such a value?
>
> Thanks,
>
> Eda
>
> Matthew Knepley <knepley at gmail.com>, 11 Mar 2019 Pzt, 15:56 tarihinde
> şunu yazdı:
>
>> On Mon, Mar 11, 2019 at 8:27 AM Eda Oktay via petsc-users <
>> petsc-users at mcs.anl.gov> wrote:
>>
>>> Hello,
>>>
>>> I have a following part of a code which tries to change the nonzero
>>> values of matrix L with -1. However in MatSetValues line, something happens
>>> and some of the values in matrix turns into 1.99665e-314 instead of -1.
>>> Type of arr is defined as PetscScalar and arr is produced correctly. What
>>> can be the problem, is there a mistake about types?
>>>
>>> Thanks,
>>>
>>> Eda
>>>
>>>
>>> for(rw = mm; rw<nn; ++rw){
>>>
>>>             ierr = MatGetRow(L,rw,&ncols,&cols,&vals);CHKERRQ(ierr);
>>>
>>>             s = sizeof(vals);
>>>
>>
>> This is wrong. sizeof(vals) gives bytes, not entries. Why don't you just
>> use ncols here?
>>
>>   Matt
>>
>>
>>>             ierr = PetscMalloc1(s,&arr);CHKERRQ(ierr);
>>>
>>>             for(j=0;j<s;++j){
>>>
>>>                 arr[j]=-1.0;
>>>             }
>>>             ierr =
>>> MatSetValues(NSymmA,1,&rw,ncols,cols,arr,INSERT_VALUES);CHKERRQ(ierr);
>>>             ierr = MatRestoreRow(L,rw,&ncols,&cols,&vals);CHKERRQ(ierr);
>>>         }
>>>
>>
>>
>> --
>> 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/20190311/0e4e4b26/attachment-0001.html>


More information about the petsc-users mailing list