<div dir="ltr"><div dir="ltr">On Tue, Dec 13, 2022 at 1:52 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 class="msg-4449003690197555567">
<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_-6433240073591726250WordSection1">
<p class="MsoNormal">Ok I’ll check that, thanks for taking a look! By the way, when I reduce the domain size this error doesn’t appear anymore, so I don’t know whether gdb just cannot handle the memory, and start to cut things off which is causing the seg fault.</p></div></div></div></blockquote><div><br></div><div>It is not the size, it is your arguments. See here</div><div><br></div><div> mat=@0x555555927e10: 0x555557791bb0, diag=5, offDiag=0)</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="msg-4449003690197555567"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="m_-6433240073591726250WordSection1"><p class="MsoNormal"><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal" style="margin-bottom:12pt"><b><span style="font-size:12pt;color:black">From:
</span></b><span style="font-size:12pt;color:black">Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>><br>
<b>Date: </b>Tuesday, December 13, 2022 at 2:49 PM<br>
<b>To: </b>Yuyun Yang <<a href="mailto:yyang85@alumni.stanford.edu" target="_blank">yyang85@alumni.stanford.edu</a>><br>
<b>Cc: </b>petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject: </b>Re: [petsc-users] Seg fault in gdb but program runs<u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal">On Tue, Dec 13, 2022 at 1:14 AM Yuyun Yang <<a href="mailto:yyang85@alumni.stanford.edu" target="_blank">yyang85@alumni.stanford.edu</a>> wrote:<u></u><u></u></p>
</div>
<div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Here is the error message:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">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);<u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">d_nnz and o_nnz are pointers, and they are supposed to hold arrays of the number of nonzero in each row,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">You seem to be passing integers.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> Thanks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> Matt<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">On Tue, Dec 13, 2022 at 12:41 PM Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">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:<u></u><u></u></p>
</div>
<div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal">Hello team,<u></u><u></u></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?<u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">The only PETSc calls are the MatGetOwnershipRange() calls, which have not changed, so I think this is unlikely.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<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:<u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">What is the debugger output?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> Thanks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> Matt<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p>// calculate the exact nonzero structure which results from the kronecker outer product of left and right <u></u><u></u></p>
<p>// d_nnz = diagonal nonzero structure, o_nnz = off-diagonal nonzero structure
<span style="color:rgb(234,234,234)"> </span><u></u><u></u></p>
<p>void kronConvert_symbolic(const Spmat &left, const Spmat &right, Mat &mat, PetscInt* d_nnz, PetscInt* o_nnz) <u></u><u></u></p>
<p>{ <u></u><u></u></p>
<p> size_t rightRowSize = right.size(1); <u></u><u></u></p>
<p> size_t rightColSize = right.size(2); <u></u><u></u></p>
<p> <u></u><u></u></p>
<p> PetscInt Istart,Iend; // rows owned by current processor <u></u><u></u></p>
<p> PetscInt Jstart,Jend; // cols owned by current processor <u></u><u></u></p>
<p> <u></u><u></u></p>
<p> // allocate space for mat<span style="color:rgb(130,130,130)"> </span> <u></u><u></u></p>
<p> MatGetOwnershipRange(mat,&Istart,&Iend); <u></u><u></u></p>
<p> MatGetOwnershipRangeColumn(mat,&Jstart,&Jend); <u></u><u></u></p>
<p> PetscInt m = Iend - Istart; <u></u><u></u></p>
<p> <u></u><u></u></p>
<p> for (int ii=0; ii<m; ii++) { d_nnz[ii] = 0; } <u></u><u></u></p>
<p> for (int ii=0; ii<m; ii++) { o_nnz[ii] = 0; } <u></u><u></u></p>
<p> <u></u><u></u></p>
<p> // iterate over only nnz entries <u></u><u></u></p>
<p> Spmat::const_row_iter IiL,IiR; <u></u><u></u></p>
<p> Spmat::const_col_iter JjL,JjR; <u></u><u></u></p>
<p> double valL=0, valR=0, val=0; <u></u><u></u></p>
<p> PetscInt row,col; <u></u><u></u></p>
<p> size_t rowL,colL,rowR,colR; <u></u><u></u></p>
<p> <u></u><u></u></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)">
</span><u></u><u></u></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++) { </span><u></u><u></u></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++) { </span><u></u><u></u></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; </span><u></u><u></u></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; </span><u></u><u></u></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; </span><u></u><u></u></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)">; } </span><u></u><u></u></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><u></u><u></u></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)"> </span><u></u><u></u></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++) { </span><u></u><u></u></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++) { </span><u></u><u></u></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; </span><u></u><u></u></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; </span><u></u><u></u></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; </span><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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; </span><u></u><u></u></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; </span><u></u><u></u></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; </span><u></u><u></u></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><u></u><u></u></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)"> </span><u></u><u></u></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]++; \</span><u></u><u></u></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><u></u><u></u></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\</span><u></u><u></u></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]++; } </span><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></p>
<p> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thank you,<u></u><u></u></p>
<p class="MsoNormal">Yuyun<u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">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<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">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<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</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>