<div dir="ltr"><div dir="ltr">On Tue, Dec 13, 2022 at 1:14 AM Yuyun Yang <<a href="mailto:yyang85@alumni.stanford.edu">yyang85@alumni.stanford.edu</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Here is the error message:</div><div><br></div><div>Program received signal SIGSEGV, Segmentation fault.<br>0x00005555555e73b7 in kronConvert (left=..., right=..., <br> mat=@0x555555927e10: 0x555557791bb0, diag=5, offDiag=0)<br> at /home/yuyun/scycle-2/source/spmat.cpp:265<br>265 kronConvert_symbolic(left,right,mat,d_nnz,o_nnz);</div></div></blockquote><div><br></div><div>d_nnz and o_nnz are pointers, and they are supposed to hold arrays of the number of nonzero in each row,</div><div>You seem to be passing integers.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Dec 13, 2022 at 12:41 PM Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Mon, Dec 12, 2022 at 9:56 PM Yuyun Yang <<a href="mailto:yyang85@alumni.stanford.edu" target="_blank">yyang85@alumni.stanford.edu</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
<div lang="EN-US">
<div>
<p class="MsoNormal">Hello team,</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I’m debugging my code using gdb. The program runs just fine if I don’t debug it, but when I use gdb, it seg faults at a place where it never experienced any seg fault when I debugged it 1-2 years ago. I wonder if this might be caused by
the PETSc version change?</p></div></div></div></blockquote><div><br></div><div>The only PETSc calls are the MatGetOwnershipRange() calls, which have not changed, so I think this is unlikely.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div lang="EN-US"><div><p class="MsoNormal"> Or something wrong with gdb itself? I’ve included the code block that is problematic for you to take a look at what might be wrong – seg fault happens when this function is called. For context, Spmat is a class of sparse matrices
in the code:</p></div></div></div></blockquote><div><br></div><div>What is the debugger output?</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> <span style="font-size:11pt"> </span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div lang="EN-US"><div>
<p><span>// calculate the exact nonzero structure which results from the kronecker outer product of left and</span><span>
</span><span>right </span><span> </span></p>
<p><span>// d_nnz = diagonal nonzero structure, o_nnz = off-diagonal nonzero structure</span><span> </span><span>
</span><span><span style="color:rgb(234,234,234)"> </span></span></p>
<p><span>void</span><span> </span><span>kronConvert_symbolic</span><span>(</span><span>const</span><span>
</span><span>Spmat</span><span> &</span><span>left</span><span>,
</span><span>const</span><span> </span><span>Spmat</span><span> &</span><span>right</span><span>,
</span><span>Mat</span><span> &</span><span>mat</span><span>,
</span><span>PetscInt</span><span>* </span><span>d_nnz</span><span>,
</span><span>PetscInt</span><span>* </span><span>o_nnz</span><span>)</span><span> </span></p>
<p><span>{</span><span> </span></p>
<p><span> </span><span>size_t</span><span>
</span><span>rightRowSize</span><span> = right.size(1); </span>
<span> </span></p>
<p><span> </span><span>size_t</span><span>
</span><span>rightColSize</span><span> = right.size(2); </span>
<span> </span></p>
<p><span> </span></p>
<p><span> </span><span>PetscInt</span><span>
</span><span>Istart</span><span>,</span><span>Iend</span><span>;
</span><span>// rows owned by current processor </span><span> </span></p>
<p><span> </span><span>PetscInt</span><span>
</span><span>Jstart</span><span>,</span><span>Jend</span><span>;
</span><span>// cols owned by current processor </span><span> </span></p>
<p><span> </span></p>
<p><span> </span><span>// allocate space for mat</span><span><span style="color:rgb(130,130,130)"> </span></span><span>
</span><span> </span></p>
<p><span> </span><span>MatGetOwnershipRange(mat,&Istart,&Iend);
</span><span> </span></p>
<p><span> </span><span>MatGetOwnershipRangeColumn(mat,&Jstart,&Jend);
</span><span> </span></p>
<p><span> </span><span>PetscInt</span><span>
</span><span>m</span><span> = Iend - Istart;</span><span> </span></p>
<p><span> </span></p>
<p><span> </span><span>for</span><span> (</span><span>int</span><span>
</span><span>ii</span><span>=0; ii<m; ii++) { d_nnz[ii] = 0; }</span><span> </span></p>
<p><span> </span><span>for</span><span> (</span><span>int</span><span>
</span><span>ii</span><span>=0; ii<m; ii++) { o_nnz[ii] = 0; }</span><span> </span></p>
<p><span> </span></p>
<p><span> </span><span>// iterate over only nnz entries
</span><span> </span></p>
<p><span> </span><span>Spmat</span><span>::</span><span>const_row_iter</span><span>
</span><span>IiL</span><span>,</span><span>IiR</span><span>;
</span><span> </span></p>
<p><span> </span><span>Spmat</span><span>::</span><span>const_col_iter</span><span>
</span><span>JjL</span><span>,</span><span>JjR</span><span>;
</span><span> </span></p>
<p><span> </span><span>double</span><span>
</span><span>valL</span><span>=0, </span><span>valR</span><span>=0,
</span><span>val</span><span>=0;</span><span> </span></p>
<p><span> </span><span>PetscInt</span><span>
</span><span>row</span><span>,</span><span>col</span><span>;</span><span> </span></p>
<p><span> </span><span>size_t</span><span>
</span><span>rowL</span><span>,</span><span>colL</span><span>,</span><span>rowR</span><span>,</span><span>colR</span><span>;</span><span>
</span></p>
<p><span> <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(130,130,130)">// loop over all values in left </span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(119,205,255)">for</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> (IiL=left._mat.begin(); IiL!=left._mat.end(); IiL++) { <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(119,205,255)">for</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> (JjL=(IiL->second).begin(); JjL!=(IiL->second).end(); JjL++) { <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> rowL = IiL->first; <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> colL = JjL->first; <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> valL = JjL->second; <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(119,205,255)">if</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> (valL==0) {
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(119,205,255)">continue</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">; } <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(130,130,130)">// loop over all values in right
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(119,205,255)">for</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> (IiR=right._mat.begin(); IiR!=right._mat.end(); IiR++) { <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(119,205,255)">for</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> (JjR=(IiR->second).begin(); JjR!=(IiR->second).end(); JjR++) { <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> rowR = IiR->first; <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> colR = JjR->first; <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> valR = JjR->second; <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(130,130,130)">// the new values and coordinates for the product matrix
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> </span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(130,130,130)"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> val = valL*valR; <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> row = rowL*rightRowSize + rowR; <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> col = colL*rightColSize + colR; <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(117,162,77)">PetscInt</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(206,208,116)">ii</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> = row - Istart;
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(130,130,130)">// array index for d_nnz and o_nnz
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(119,205,255)">if</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> (val!=0 && row >= Istart && row < Iend && col >= Jstart && col < Jend) { d_nnz[ii]++; \<u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">} <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(119,205,255)">if</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> ( (val!=0 && row >= Istart && row < Iend) && (col < Jstart || col >= Jend) ) { o_nnz[i\<u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">i]++; } <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> } <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> } <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> } <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)"> } <u></u><u></u></span></p>
<p class="MsoNormal" style="background:rgb(29,29,29)"><span style="font-size:11.5pt;font-family:"Andale Mono";color:rgb(234,234,234)">} <u></u><u></u></span></p>
<p><span> </span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal">Thank you,</p>
<p class="MsoNormal">Yuyun</p>
</div>
</div>
</div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>