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 <[email protected]>, 11 Mar 2019 Pzt, 15:56 tarihinde şunu yazdı: > On Mon, Mar 11, 2019 at 8:27 AM Eda Oktay via petsc-users < > [email protected]> 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/> >
