<div dir="ltr"><div dir="ltr">On Mon, Dec 12, 2022 at 9:56 PM 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 class="msg-1785767850578359496">
<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_-497379444687013337WordSection1">
<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 class="msg-1785767850578359496"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="m_-497379444687013337WordSection1"><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 class="msg-1785767850578359496"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="m_-497379444687013337WordSection1">
<p class="m_-497379444687013337p1"><span class="m_-497379444687013337s1">// calculate the exact nonzero structure which results from the kronecker outer product of left and</span><span class="m_-497379444687013337s2">
</span><span class="m_-497379444687013337s3">right </span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p1"><span class="m_-497379444687013337s1">// d_nnz = diagonal nonzero structure, o_nnz = off-diagonal nonzero structure</span><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s2">
</span><span class="m_-497379444687013337apple-converted-space"><span style="color:rgb(234,234,234)"> </span></span></p>
<p class="m_-497379444687013337p3"><span class="m_-497379444687013337s4">void</span><span class="m_-497379444687013337s2"> </span><span class="m_-497379444687013337s1">kronConvert_symbolic</span><span class="m_-497379444687013337s2">(</span><span class="m_-497379444687013337s5">const</span><span class="m_-497379444687013337s2">
</span><span class="m_-497379444687013337s4">Spmat</span><span class="m_-497379444687013337s2"> &</span><span class="m_-497379444687013337s1">left</span><span class="m_-497379444687013337s2">,
</span><span class="m_-497379444687013337s5">const</span><span class="m_-497379444687013337s2"> </span><span class="m_-497379444687013337s4">Spmat</span><span class="m_-497379444687013337s2"> &</span><span class="m_-497379444687013337s1">right</span><span class="m_-497379444687013337s2">,
</span><span class="m_-497379444687013337s4">Mat</span><span class="m_-497379444687013337s2"> &</span><span class="m_-497379444687013337s1">mat</span><span class="m_-497379444687013337s2">,
</span><span class="m_-497379444687013337s4">PetscInt</span><span class="m_-497379444687013337s2">* </span><span class="m_-497379444687013337s1">d_nnz</span><span class="m_-497379444687013337s2">,
</span><span class="m_-497379444687013337s4">PetscInt</span><span class="m_-497379444687013337s1">* </span><span class="m_-497379444687013337s6">o_nnz</span><span class="m_-497379444687013337s1">)</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337s1">{</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s4">size_t</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">rightRowSize</span><span class="m_-497379444687013337s1"> = right.size(1); </span>
<span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s4">size_t</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">rightColSize</span><span class="m_-497379444687013337s1"> = right.size(2); </span>
<span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p4"><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s4">PetscInt</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">Istart</span><span class="m_-497379444687013337s1">,</span><span class="m_-497379444687013337s6">Iend</span><span class="m_-497379444687013337s1">;
</span><span class="m_-497379444687013337s3">// rows owned by current processor </span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s4">PetscInt</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">Jstart</span><span class="m_-497379444687013337s1">,</span><span class="m_-497379444687013337s6">Jend</span><span class="m_-497379444687013337s1">;
</span><span class="m_-497379444687013337s3">// cols owned by current processor </span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p4"><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s3">// allocate space for mat</span><span class="m_-497379444687013337apple-converted-space"><span style="color:rgb(130,130,130)"> </span></span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s1">MatGetOwnershipRange(mat,&Istart,&Iend);
</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s1">MatGetOwnershipRangeColumn(mat,&Jstart,&Jend);
</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s4">PetscInt</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">m</span><span class="m_-497379444687013337s1"> = Iend - Istart;</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p4"><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s5">for</span><span class="m_-497379444687013337s1"> (</span><span class="m_-497379444687013337s4">int</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">ii</span><span class="m_-497379444687013337s1">=0; ii<m; ii++) { d_nnz[ii] = 0; }</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s5">for</span><span class="m_-497379444687013337s1"> (</span><span class="m_-497379444687013337s4">int</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">ii</span><span class="m_-497379444687013337s1">=0; ii<m; ii++) { o_nnz[ii] = 0; }</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p4"><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s3">// iterate over only nnz entries
</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s7">Spmat</span><span class="m_-497379444687013337s1">::</span><span class="m_-497379444687013337s4">const_row_iter</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">IiL</span><span class="m_-497379444687013337s1">,</span><span class="m_-497379444687013337s6">IiR</span><span class="m_-497379444687013337s1">;
</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s7">Spmat</span><span class="m_-497379444687013337s1">::</span><span class="m_-497379444687013337s4">const_col_iter</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">JjL</span><span class="m_-497379444687013337s1">,</span><span class="m_-497379444687013337s6">JjR</span><span class="m_-497379444687013337s1">;
</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s4">double</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">valL</span><span class="m_-497379444687013337s1">=0, </span><span class="m_-497379444687013337s6">valR</span><span class="m_-497379444687013337s1">=0,
</span><span class="m_-497379444687013337s6">val</span><span class="m_-497379444687013337s1">=0;</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s4">PetscInt</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">row</span><span class="m_-497379444687013337s1">,</span><span class="m_-497379444687013337s6">col</span><span class="m_-497379444687013337s1">;</span><span class="m_-497379444687013337apple-converted-space"> </span></p>
<p class="m_-497379444687013337p2"><span class="m_-497379444687013337apple-converted-space"> </span><span class="m_-497379444687013337s4">size_t</span><span class="m_-497379444687013337s1">
</span><span class="m_-497379444687013337s6">rowL</span><span class="m_-497379444687013337s1">,</span><span class="m_-497379444687013337s6">colL</span><span class="m_-497379444687013337s1">,</span><span class="m_-497379444687013337s6">rowR</span><span class="m_-497379444687013337s1">,</span><span class="m_-497379444687013337s6">colR</span><span class="m_-497379444687013337s1">;</span><span class="m_-497379444687013337apple-converted-space">
</span></p>
<p class="m_-497379444687013337p4"><span class="m_-497379444687013337apple-converted-space"> <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 class="m_-497379444687013337p4"><span class="m_-497379444687013337apple-converted-space"> </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" 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>