<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 2, 2017, at 10:25 PM, Austin Herrema <<a href="mailto:aherrema@iastate.edu" class="">aherrema@iastate.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello all,<div class=""><br class=""></div><div class="">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 class=""><br clear="all" class=""><div class=""><div class=""><font color="#666666" class=""> ! PETSc variable declaration</font></div><div class=""><font color="#666666" class=""> Mat LHS</font></div><div class=""><font color="#666666" class=""> PetscErrorCode ier</font></div><div class=""><font color="#666666" class=""> PetscInt idx1(nsd*nsd*nshl*nshl), idx2(nsd*nsd*nshl*nshl)</font></div><div class=""><font color="#666666" class=""> PetscScalar vals(nsd*nsd*nshl*nshl)</font><br class=""><br class=""> <font color="#666666" class="">! Code for filling in index and value arrays... I've verified that there are 2304 elements in each array.</font><br class=""><br class=""><font color="#666666" class=""> ! Fill in values<br class=""> call MatSetValues(LHS, nvals, idx1, nvals, idx2, vals, ADD_VALUES, ier)</font><br class=""></div><br class="">Upon executing this, I get a general segmentation violation error. Running in Valgrind I get:<br class=""><br class=""><div class=""><font color="#666666" class="">==87676== Invalid read of size 8</font></div><div class=""><font color="#666666" class="">==87676== at 0x1008D1F45: MatSetValues_SeqAIJ (aij.c:461)</font></div><div class=""><font color="#666666" class="">==87676== by 0x1004C523C: MatSetValues (matrix.c:1190)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10053F1A5: matsetvalues_ (matrixf.c:696)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10005F47D: petsc_fillmat_ (petsc_fillMat.F90:78)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10005E5C9: intelmass_shell_ (shell_IntElmAss.F90:330)</font></div><div class=""><font color="#666666" class="">==87676== by 0x100057259: solflowgmres_ (solflow.F90:125)</font></div><div class=""><font color="#666666" class="">==87676== by 0x100051051: MAIN__ (driver.F90:140)</font></div><div class=""><font color="#666666" class="">==87676== by 0x1000545C4: main (driver.F90:7)</font></div><div class=""><font color="#666666" class="">==87676== Address 0x10a4dac60 is 0 bytes after a block of size 18,432 alloc'd</font></div><div class=""><font color="#666666" class="">==87676== at 0x100088681: malloc (in /usr/local/Cellar/valgrind/3.12.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10005EF47: petsc_fillmat_ (petsc_fillMat.F90:23)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10005E5C9: intelmass_shell_ (shell_IntElmAss.F90:330)</font></div><div class=""><font color="#666666" class="">==87676== by 0x100057259: solflowgmres_ (solflow.F90:125)</font></div><div class=""><font color="#666666" class="">==87676== by 0x100051051: MAIN__ (driver.F90:140)</font></div><div class=""><font color="#666666" class="">==87676== by 0x1000545C4: main (driver.F90:7)</font></div><div class=""><font color="#666666" class="">==87676==</font></div><div class=""><font color="#666666" class="">==87676== Conditional jump or move depends on uninitialised value(s)</font></div><div class=""><font color="#666666" class="">==87676== at 0x1008D1F57: MatSetValues_SeqAIJ (aij.c:463)</font></div><div class=""><font color="#666666" class="">==87676== by 0x1004C523C: MatSetValues (matrix.c:1190)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10053F1A5: matsetvalues_ (matrixf.c:696)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10005F47D: petsc_fillmat_ (petsc_fillMat.F90:78)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10005E5C9: intelmass_shell_ (shell_IntElmAss.F90:330)</font></div><div class=""><font color="#666666" class="">==87676== by 0x100057259: solflowgmres_ (solflow.F90:125)</font></div><div class=""><font color="#666666" class="">==87676== by 0x100051051: MAIN__ (driver.F90:140)</font></div><div class=""><font color="#666666" class="">==87676== by 0x1000545C4: main (driver.F90:7)</font></div><div class=""><font color="#666666" class="">==87676==</font></div><div class=""><font color="#666666" class="">==87676== Conditional jump or move depends on uninitialised value(s)</font></div><div class=""><font color="#666666" class="">==87676== at 0x1008D1F62: MatSetValues_SeqAIJ (aij.c:463)</font></div><div class=""><font color="#666666" class="">==87676== by 0x1004C523C: MatSetValues (matrix.c:1190)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10053F1A5: matsetvalues_ (matrixf.c:696)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10005F47D: petsc_fillmat_ (petsc_fillMat.F90:78)</font></div><div class=""><font color="#666666" class="">==87676== by 0x10005E5C9: intelmass_shell_ (shell_IntElmAss.F90:330)</font></div><div class=""><font color="#666666" class="">==87676== by 0x100057259: solflowgmres_ (solflow.F90:125)</font></div><div class=""><font color="#666666" class="">==87676== by 0x100051051: MAIN__ (driver.F90:140)</font></div><div class=""><font color="#666666" class="">==87676== by 0x1000545C4: main (driver.F90:7)</font></div><div class=""><font color="#666666" class="">==87676==</font></div><br class=""><font class="">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 class="">why </i>the error is being produced. Strangely, if I try to set the matrix values in a few smaller chunks, i.e.<br class=""></font><br class=""><div class=""><font color="#666666" class=""> call MatSetValues(LHS, 500, idx1(1:500), 500, idx2(1:500), vals(1:500), ADD_VALUES, ier)</font></div><div class=""><font color="#666666" class=""> call MatSetValues(LHS, 500, idx1(501:1000), 500, idx2(501:1000), vals(501:1000), ADD_VALUES, ier)</font></div><div class=""><font color="#666666" class=""> call MatSetValues(LHS, 500, idx1(1001:1500), 500, idx2(1001:1500), vals(1001:1500), ADD_VALUES, ier)</font></div><div class=""><font color="#666666" class=""> call MatSetValues(LHS, 500, idx1(1501:2000), 500, idx2(1501:2000), vals(1501:2000), ADD_VALUES, ier)</font></div><div class=""><font color="#666666" class=""> call MatSetValues(LHS, 304, idx1(2001:2304), 304, idx2(2001:2304), vals(2001:2304), ADD_VALUES, ier)</font></div><br class=""></div></div></div></div></blockquote><div><br class=""></div><div>vals is supposed to be a 2D array of size nvals*nvals; it seems to me that the size of your vals is nvals (supposedly, nsd*nsd*nshl*nshl)</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><font class="">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 class=""><br class="">Thank you for any help!<br class="">Austin</font></div><div class=""><br class=""></div><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature"><div dir="ltr" class=""><div dir="ltr" style="color:rgb(136,136,136);font-size:12.8px" class=""><b style="font-size:12.8px" class=""><font color="#666666" class="">Austin Herrema</font></b><br class=""></div><div dir="ltr" style="color:rgb(136,136,136);font-size:12.8px" class=""><div class=""><font color="#999999" class="">PhD Student | Graduate Research Assistant | Iowa State University</font></div><div class=""><font color="#999999" class="">Wind Energy Science, Engineering, and Policy | Mechanical Engineering</font></div></div></div></div></div></div>
</div></blockquote></div><br class=""></body></html>