[petsc-users] Problem in MatSetValues
Matthew Knepley
knepley at gmail.com
Mon Mar 11 07:56:11 CDT 2019
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/4dc15ea4/attachment.html>
More information about the petsc-users
mailing list