<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:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@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="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Matthew Knepley <knepley@gmail.com><br>
<b>Date: </b>Tuesday, December 13, 2022 at 2:49 PM<br>
<b>To: </b>Yuyun Yang <yyang85@alumni.stanford.edu><br>
<b>Cc: </b>petsc-users <petsc-users@mcs.anl.gov><br>
<b>Subject: </b>Re: [petsc-users] Seg fault in gdb but program runs<o:p></o:p></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">yyang85@alumni.stanford.edu</a>> wrote:<o:p></o:p></p>
</div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Here is the error message:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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);<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></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,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">You seem to be passing integers.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> Matt<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;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:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;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:<o:p></o:p></p>
</div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Hello team,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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?<o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The only PETSc calls are the MatGetOwnershipRange() calls, which have not changed, so I think this is unlikely.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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:<o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">What is the debugger output?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> Matt<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;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 <o:p></o:p></p>
<p>// d_nnz = diagonal nonzero structure, o_nnz = off-diagonal nonzero structure
<span style="color:#EAEAEA"> </span><o:p></o:p></p>
<p>void kronConvert_symbolic(const Spmat &left, const Spmat &right, Mat &mat, PetscInt* d_nnz, PetscInt* o_nnz) <o:p></o:p></p>
<p>{ <o:p></o:p></p>
<p> size_t rightRowSize = right.size(1); <o:p></o:p></p>
<p> size_t rightColSize = right.size(2); <o:p></o:p></p>
<p> <o:p></o:p></p>
<p> PetscInt Istart,Iend; // rows owned by current processor <o:p></o:p></p>
<p> PetscInt Jstart,Jend; // cols owned by current processor <o:p></o:p></p>
<p> <o:p></o:p></p>
<p> // allocate space for mat<span style="color:#828282"> </span> <o:p></o:p></p>
<p> MatGetOwnershipRange(mat,&Istart,&Iend); <o:p></o:p></p>
<p> MatGetOwnershipRangeColumn(mat,&Jstart,&Jend); <o:p></o:p></p>
<p> PetscInt m = Iend - Istart; <o:p></o:p></p>
<p> <o:p></o:p></p>
<p> for (int ii=0; ii<m; ii++) { d_nnz[ii] = 0; } <o:p></o:p></p>
<p> for (int ii=0; ii<m; ii++) { o_nnz[ii] = 0; } <o:p></o:p></p>
<p> <o:p></o:p></p>
<p> // iterate over only nnz entries <o:p></o:p></p>
<p> Spmat::const_row_iter IiL,IiR; <o:p></o:p></p>
<p> Spmat::const_col_iter JjL,JjR; <o:p></o:p></p>
<p> double valL=0, valR=0, val=0; <o:p></o:p></p>
<p> PetscInt row,col; <o:p></o:p></p>
<p> size_t rowL,colL,rowR,colR; <o:p></o:p></p>
<p> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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">
</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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++) { </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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++) { </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> rowL = IiL->first; </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> colL = JjL->first; </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> valL = JjL->second; </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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">; } </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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++) { </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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++) { </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> rowR = IiR->first; </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> colR = JjR->first; </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> valR = JjR->second; </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> val = valL*valR; </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> row = rowL*rightRowSize + rowR; </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> col = colL*rightColSize + colR; </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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]++; \</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">} </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;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\</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">i]++; } </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> } </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> } </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> } </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA"> } </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#1D1D1D">
<span style="font-size:11.5pt;font-family:"Andale Mono";color:#EAEAEA">} </span><o:p></o:p></p>
<p> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thank you,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Yuyun<o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">-- <o:p></o:p></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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">-- <o:p></o:p></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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>