<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Andale Mono";
        panose-1:2 11 5 9 0 0 0 0 0 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif;}
p.p1, li.p1, div.p1
        {mso-style-name:p1;
        margin:0in;
        background:#1D1D1D;
        font-size:11.5pt;
        font-family:"Andale Mono";
        color:#828282;}
p.p2, li.p2, div.p2
        {mso-style-name:p2;
        margin:0in;
        background:#1D1D1D;
        font-size:11.5pt;
        font-family:"Andale Mono";
        color:#EAEAEA;}
p.p3, li.p3, div.p3
        {mso-style-name:p3;
        margin:0in;
        background:#1D1D1D;
        font-size:11.5pt;
        font-family:"Andale Mono";
        color:#CED074;}
p.p4, li.p4, div.p4
        {mso-style-name:p4;
        margin:0in;
        background:#1D1D1D;
        font-size:11.5pt;
        font-family:"Andale Mono";
        color:#EAEAEA;}
span.s2
        {mso-style-name:s2;
        color:#EAEAEA;}
span.s3
        {mso-style-name:s3;
        color:#828282;}
span.s4
        {mso-style-name:s4;
        color:#75A24D;}
span.s5
        {mso-style-name:s5;
        color:#77CDFF;}
span.s6
        {mso-style-name:s6;
        color:#CED074;}
span.s7
        {mso-style-name:s7;
        color:#CC734D;}
span.s1
        {mso-style-name:s1;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hello team,</p>
<p class="MsoNormal"><o:p> </o:p></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? 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>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="p1"><span class="s1">// calculate the exact nonzero structure which results from the kronecker outer product of left and</span><span class="s2">
</span><span class="s3">right </span><span class="apple-converted-space">                                                                                             </span></p>
<p class="p1"><span class="s1">// d_nnz = diagonal nonzero structure, o_nnz = off-diagonal nonzero structure</span><span class="apple-converted-space"> </span><span class="s2">
</span><span class="apple-converted-space"><span style="color:#EAEAEA">                     </span></span></p>
<p class="p3"><span class="s4">void</span><span class="s2"> </span><span class="s1">kronConvert_symbolic</span><span class="s2">(</span><span class="s5">const</span><span class="s2">
</span><span class="s4">Spmat</span><span class="s2"> &</span><span class="s1">left</span><span class="s2">,
</span><span class="s5">const</span><span class="s2"> </span><span class="s4">Spmat</span><span class="s2"> &</span><span class="s1">right</span><span class="s2">,
</span><span class="s4">Mat</span><span class="s2"> &</span><span class="s1">mat</span><span class="s2">,
</span><span class="s4">PetscInt</span><span class="s2">* </span><span class="s1">d_nnz</span><span class="s2">,
</span><span class="s4">PetscInt</span><span class="s1">* </span><span class="s6">o_nnz</span><span class="s1">)</span><span class="apple-converted-space">                                                                                           </span></p>
<p class="p2"><span class="s1">{</span><span class="apple-converted-space">                                                                                                   </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s4">size_t</span><span class="s1">
</span><span class="s6">rightRowSize</span><span class="s1"> = right.size(1); </span>
<span class="apple-converted-space">                                                             </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s4">size_t</span><span class="s1">
</span><span class="s6">rightColSize</span><span class="s1"> = right.size(2); </span>
<span class="apple-converted-space">                                                             </span></p>
<p class="p4"><span class="apple-converted-space">                                                                                                    </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s4">PetscInt</span><span class="s1">
</span><span class="s6">Istart</span><span class="s1">,</span><span class="s6">Iend</span><span class="s1">;
</span><span class="s3">// rows owned by current processor </span><span class="apple-converted-space">                                         </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s4">PetscInt</span><span class="s1">
</span><span class="s6">Jstart</span><span class="s1">,</span><span class="s6">Jend</span><span class="s1">;
</span><span class="s3">// cols owned by current processor </span><span class="apple-converted-space">                                         </span></p>
<p class="p4"><span class="apple-converted-space">                                                                                                    </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s3">// allocate space for mat</span><span class="apple-converted-space"><span style="color:#828282"> </span></span><span class="s1">
</span><span class="apple-converted-space">                                                                       </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s1">MatGetOwnershipRange(mat,&Istart,&Iend);
</span><span class="apple-converted-space">                                                         </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s1">MatGetOwnershipRangeColumn(mat,&Jstart,&Jend);
</span><span class="apple-converted-space">                                                   </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s4">PetscInt</span><span class="s1">
</span><span class="s6">m</span><span class="s1"> = Iend - Istart;</span><span class="apple-converted-space">                                                                       </span></p>
<p class="p4"><span class="apple-converted-space">                                                                                                    </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s5">for</span><span class="s1"> (</span><span class="s4">int</span><span class="s1">
</span><span class="s6">ii</span><span class="s1">=0; ii<m; ii++) { d_nnz[ii] = 0; }</span><span class="apple-converted-space">                                                     </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s5">for</span><span class="s1"> (</span><span class="s4">int</span><span class="s1">
</span><span class="s6">ii</span><span class="s1">=0; ii<m; ii++) { o_nnz[ii] = 0; }</span><span class="apple-converted-space">                                                     </span></p>
<p class="p4"><span class="apple-converted-space">                                                                                                    </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s3">// iterate over only nnz entries
</span><span class="apple-converted-space">                                                                 </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s7">Spmat</span><span class="s1">::</span><span class="s4">const_row_iter</span><span class="s1">
</span><span class="s6">IiL</span><span class="s1">,</span><span class="s6">IiR</span><span class="s1">;
</span><span class="apple-converted-space">                                                                   </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s7">Spmat</span><span class="s1">::</span><span class="s4">const_col_iter</span><span class="s1">
</span><span class="s6">JjL</span><span class="s1">,</span><span class="s6">JjR</span><span class="s1">;
</span><span class="apple-converted-space">                                                                   </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s4">double</span><span class="s1">
</span><span class="s6">valL</span><span class="s1">=0, </span><span class="s6">valR</span><span class="s1">=0,
</span><span class="s6">val</span><span class="s1">=0;</span><span class="apple-converted-space">                                                                     </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s4">PetscInt</span><span class="s1">
</span><span class="s6">row</span><span class="s1">,</span><span class="s6">col</span><span class="s1">;</span><span class="apple-converted-space">                                                                                 </span></p>
<p class="p2"><span class="apple-converted-space">  </span><span class="s4">size_t</span><span class="s1">
</span><span class="s6">rowL</span><span class="s1">,</span><span class="s6">colL</span><span class="s1">,</span><span class="s6">rowR</span><span class="s1">,</span><span class="s6">colR</span><span class="s1">;</span><span class="apple-converted-space"> 
                                                                      </span></p>
<p class="p4"><span class="apple-converted-space">               <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> 
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#828282">// loop over all values in left </span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">                                                                  <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> 
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#77CDFF">for</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> (IiL=left._mat.begin(); IiL!=left._mat.end(); IiL++) {                                        <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">   
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#77CDFF">for</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> (JjL=(IiL->second).begin(); JjL!=(IiL->second).end(); JjL++) {                              <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">      rowL = IiL->first;                                                                            <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">      colL = JjL->first;                                                                            <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">      valL = JjL->second;                                                                           <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">     
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#77CDFF">if</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> (valL==0) {
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#77CDFF">continue</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">; }                                                                    <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">                                                                                                    <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">     
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#828282">// loop over all values in right
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">                                                             <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">     
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#77CDFF">for</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> (IiR=right._mat.begin(); IiR!=right._mat.end(); IiR++) {                                  <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">       
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#77CDFF">for</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> (JjR=(IiR->second).begin(); JjR!=(IiR->second).end(); JjR++) {                          <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">          rowR = IiR->first;                                                                        <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">          colR = JjR->first;                                                                        <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">          valR = JjR->second;                                                                       <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">                                                                                                    <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">         
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#828282">// the new values and coordinates for the product matrix
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">                                 </span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#828282"><o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">          val = valL*valR;                                                                          <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">          row = rowL*rightRowSize + rowR;                                                           <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">          col = colL*rightColSize + colR;                                                           <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">                                                                                                    <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">         
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#75A24D">PetscInt</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#CED074">ii</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> = row - Istart;
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#828282">// array index for d_nnz and o_nnz
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">                           <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">         
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#77CDFF">if</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> (val!=0 && row >= Istart && row < Iend && col >= Jstart && col < Jend) { d_nnz[ii]++; \<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">}                                                                                                   <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">         
</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#77CDFF">if</span><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> ( (val!=0 && row >= Istart && row < Iend) && (col < Jstart || col >= Jend) ) { o_nnz[i\<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">i]++; }                                                                                             <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">        }                                                                                           <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">      }                                                                                             <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">    }                                                                                               <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">  }                                                                                                 <o:p></o:p></span></p>
<p class="MsoNormal" style="background:#1D1D1D"><span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">}                                                                                                   <o:p></o:p></span></p>
<p class="p4"><span class="apple-converted-space">                                                                                     </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal">Thank you,</p>
<p class="MsoNormal">Yuyun</p>
</div>
</body>
</html>