<div dir="ltr">Hello all,<div><br></div><div>I'm having a strange issue when using the MatSetVals function in Fortran. The code is quite large, but relevant snippets of what I'm trying to do are below.<br><br clear="all"><div><div><font color="#666666">  ! PETSc variable declaration</font></div><div><font color="#666666">  Mat LHS</font></div><div><font color="#666666">  PetscErrorCode ier</font></div><div><font color="#666666">  PetscInt idx1(nsd*nsd*nshl*nshl), idx2(nsd*nsd*nshl*nshl)</font></div><div><font color="#666666">  PetscScalar vals(nsd*nsd*nshl*nshl)</font><br><br>  <font color="#666666">! Code for filling in index and value arrays... I've verified that there are 2304 elements in each array.</font><br><br><font color="#666666">  ! Fill in values<br>  call MatSetValues(LHS, nvals, idx1, nvals, idx2, vals, ADD_VALUES, ier)</font><br></div><br>Upon executing this, I get a general segmentation violation error. Running in Valgrind I get:<br><br><div><font color="#666666">==87676== Invalid read of size 8</font></div><div><font color="#666666">==87676==    at 0x1008D1F45: MatSetValues_SeqAIJ (aij.c:461)</font></div><div><font color="#666666">==87676==    by 0x1004C523C: MatSetValues (matrix.c:1190)</font></div><div><font color="#666666">==87676==    by 0x10053F1A5: matsetvalues_ (matrixf.c:696)</font></div><div><font color="#666666">==87676==    by 0x10005F47D: petsc_fillmat_ (petsc_fillMat.F90:78)</font></div><div><font color="#666666">==87676==    by 0x10005E5C9: intelmass_shell_ (shell_IntElmAss.F90:330)</font></div><div><font color="#666666">==87676==    by 0x100057259: solflowgmres_ (solflow.F90:125)</font></div><div><font color="#666666">==87676==    by 0x100051051: MAIN__ (driver.F90:140)</font></div><div><font color="#666666">==87676==    by 0x1000545C4: main (driver.F90:7)</font></div><div><font color="#666666">==87676==  Address 0x10a4dac60 is 0 bytes after a block of size 18,432 alloc'd</font></div><div><font color="#666666">==87676==    at 0x100088681: malloc (in /usr/local/Cellar/valgrind/3.12.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)</font></div><div><font color="#666666">==87676==    by 0x10005EF47: petsc_fillmat_ (petsc_fillMat.F90:23)</font></div><div><font color="#666666">==87676==    by 0x10005E5C9: intelmass_shell_ (shell_IntElmAss.F90:330)</font></div><div><font color="#666666">==87676==    by 0x100057259: solflowgmres_ (solflow.F90:125)</font></div><div><font color="#666666">==87676==    by 0x100051051: MAIN__ (driver.F90:140)</font></div><div><font color="#666666">==87676==    by 0x1000545C4: main (driver.F90:7)</font></div><div><font color="#666666">==87676==</font></div><div><font color="#666666">==87676== Conditional jump or move depends on uninitialised value(s)</font></div><div><font color="#666666">==87676==    at 0x1008D1F57: MatSetValues_SeqAIJ (aij.c:463)</font></div><div><font color="#666666">==87676==    by 0x1004C523C: MatSetValues (matrix.c:1190)</font></div><div><font color="#666666">==87676==    by 0x10053F1A5: matsetvalues_ (matrixf.c:696)</font></div><div><font color="#666666">==87676==    by 0x10005F47D: petsc_fillmat_ (petsc_fillMat.F90:78)</font></div><div><font color="#666666">==87676==    by 0x10005E5C9: intelmass_shell_ (shell_IntElmAss.F90:330)</font></div><div><font color="#666666">==87676==    by 0x100057259: solflowgmres_ (solflow.F90:125)</font></div><div><font color="#666666">==87676==    by 0x100051051: MAIN__ (driver.F90:140)</font></div><div><font color="#666666">==87676==    by 0x1000545C4: main (driver.F90:7)</font></div><div><font color="#666666">==87676==</font></div><div><font color="#666666">==87676== Conditional jump or move depends on uninitialised value(s)</font></div><div><font color="#666666">==87676==    at 0x1008D1F62: MatSetValues_SeqAIJ (aij.c:463)</font></div><div><font color="#666666">==87676==    by 0x1004C523C: MatSetValues (matrix.c:1190)</font></div><div><font color="#666666">==87676==    by 0x10053F1A5: matsetvalues_ (matrixf.c:696)</font></div><div><font color="#666666">==87676==    by 0x10005F47D: petsc_fillmat_ (petsc_fillMat.F90:78)</font></div><div><font color="#666666">==87676==    by 0x10005E5C9: intelmass_shell_ (shell_IntElmAss.F90:330)</font></div><div><font color="#666666">==87676==    by 0x100057259: solflowgmres_ (solflow.F90:125)</font></div><div><font color="#666666">==87676==    by 0x100051051: MAIN__ (driver.F90:140)</font></div><div><font color="#666666">==87676==    by 0x1000545C4: main (driver.F90:7)</font></div><div><font color="#666666">==87676==</font></div><br><font color="#000000">I'm not terribly experienced with Valgrind but I can't find anything too helpful in that output. It shows the traceback but I still cannot understand <i>why </i>the error is being produced. Strangely, if I try to set the matrix values in a few smaller chunks, i.e.<br></font><br><div><font color="#666666">  call MatSetValues(LHS, 500, idx1(1:500), 500, idx2(1:500), vals(1:500), ADD_VALUES, ier)</font></div><div><font color="#666666">  call MatSetValues(LHS, 500, idx1(501:1000), 500, idx2(501:1000), vals(501:1000), ADD_VALUES, ier)</font></div><div><font color="#666666">  call MatSetValues(LHS, 500, idx1(1001:1500), 500, idx2(1001:1500), vals(1001:1500), ADD_VALUES, ier)</font></div><div><font color="#666666">  call MatSetValues(LHS, 500, idx1(1501:2000), 500, idx2(1501:2000), vals(1501:2000), ADD_VALUES, ier)</font></div><div><font color="#666666">  call MatSetValues(LHS, 304, idx1(2001:2304), 304, idx2(2001:2304), vals(2001:2304), ADD_VALUES, ier)</font></div><br></div><div><font color="#000000">Then everything works with no errors. Is there some kind of limitation to how many values you can insert into a matrix at once? Would strike me as strange. I can assign elements one at a time but reducing the number of calls to MatSetVals by a factor of 2000 would be fantastic. I would be happy to provide more details of the matrix setup if necessary.<br><br>Thank you for any help!<br>Austin</font></div><div><br></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div dir="ltr" style="color:rgb(136,136,136);font-size:12.8px"><b style="font-size:12.8px"><font color="#666666">Austin Herrema</font></b><br></div><div dir="ltr" style="color:rgb(136,136,136);font-size:12.8px"><div><font color="#999999">PhD Student | Graduate Research Assistant | Iowa State University</font></div><div><font color="#999999">Wind Energy Science, Engineering, and Policy | Mechanical Engineering</font></div></div></div></div></div></div>