[petsc-users] Seg fault in gdb but program runs

Matthew Knepley knepley at gmail.com
Tue Dec 13 08:35:35 CST 2022


On Tue, Dec 13, 2022 at 1:52 AM Yuyun Yang <yyang85 at alumni.stanford.edu>
wrote:

> 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.
>

It is not the size, it is your arguments. See here

      mat=@0x555555927e10: 0x555557791bb0, diag=5, offDiag=0)

  Thanks,

     Matt


>
>
> *From: *Matthew Knepley <knepley at gmail.com>
> *Date: *Tuesday, December 13, 2022 at 2:49 PM
> *To: *Yuyun Yang <yyang85 at alumni.stanford.edu>
> *Cc: *petsc-users <petsc-users at mcs.anl.gov>
> *Subject: *Re: [petsc-users] Seg fault in gdb but program runs
>
> On Tue, Dec 13, 2022 at 1:14 AM Yuyun Yang <yyang85 at alumni.stanford.edu>
> wrote:
>
> Here is the error message:
>
>
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x00005555555e73b7 in kronConvert (left=..., right=...,
>     mat=@0x555555927e10: 0x555557791bb0, diag=5, offDiag=0)
>     at /home/yuyun/scycle-2/source/spmat.cpp:265
> 265  kronConvert_symbolic(left,right,mat,d_nnz,o_nnz);
>
>
>
> d_nnz and o_nnz are pointers, and they are supposed to hold arrays of the
> number of nonzero in each row,
>
> You seem to be passing integers.
>
>
>
>   Thanks,
>
>
>
>      Matt
>
>
>
> On Tue, Dec 13, 2022 at 12:41 PM Matthew Knepley <knepley at gmail.com>
> wrote:
>
> On Mon, Dec 12, 2022 at 9:56 PM Yuyun Yang <yyang85 at alumni.stanford.edu>
> wrote:
>
> Hello team,
>
>
>
> 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?
>
>
>
> The only PETSc calls are the MatGetOwnershipRange() calls, which have not
> changed, so I think this is unlikely.
>
>
>
> 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:
>
>
>
> What is the debugger output?
>
>
>
>   Thanks,
>
>
>
>     Matt
>
>
>
> // calculate the exact nonzero structure which results from the kronecker
> outer product of left and right
>
>
> // d_nnz = diagonal nonzero structure, o_nnz = off-diagonal nonzero
> structure
>
> void kronConvert_symbolic(const Spmat &left, const Spmat &right, Mat &mat,
> PetscInt* d_nnz, PetscInt* o_nnz)
>
>
> {
>
>
>   size_t rightRowSize = right.size(1);
>
>
>   size_t rightColSize = right.size(2);
>
>
>
>
>
>   PetscInt Istart,Iend; // rows owned by current processor
>
>
>   PetscInt Jstart,Jend; // cols owned by current processor
>
>
>
>
>
>   // allocate space for mat
>
>
>   MatGetOwnershipRange(mat,&Istart,&Iend);
>
>
>   MatGetOwnershipRangeColumn(mat,&Jstart,&Jend);
>
>
>   PetscInt m = Iend - Istart;
>
>
>
>
>
>   for (int ii=0; ii<m; ii++) { d_nnz[ii] = 0; }
>
>
>   for (int ii=0; ii<m; ii++) { o_nnz[ii] = 0; }
>
>
>
>
>
>   // iterate over only nnz entries
>
>
>   Spmat::const_row_iter IiL,IiR;
>
>
>   Spmat::const_col_iter JjL,JjR;
>
>
>   double valL=0, valR=0, val=0;
>
>
>   PetscInt row,col;
>
>
>   size_t rowL,colL,rowR,colR;
>
>
>
>
>   // loop over all values in left
>
>
>   for (IiL=left._mat.begin(); IiL!=left._mat.end(); IiL++) {
>
>
>     for (JjL=(IiL->second).begin(); JjL!=(IiL->second).end(); JjL++) {
>
>
>       rowL = IiL->first;
>
>
>       colL = JjL->first;
>
>
>       valL = JjL->second;
>
>
>       if (valL==0) { continue; }
>
>
>
>
>
>       // loop over all values in right
>
>
>       for (IiR=right._mat.begin(); IiR!=right._mat.end(); IiR++) {
>
>
>         for (JjR=(IiR->second).begin(); JjR!=(IiR->second).end(); JjR++)
> {
>
>           rowR = IiR->first;
>
>
>           colR = JjR->first;
>
>
>           valR = JjR->second;
>
>
>
>
>
>           // the new values and coordinates for the product matrix
>
>
>           val = valL*valR;
>
>
>           row = rowL*rightRowSize + rowR;
>
>
>           col = colL*rightColSize + colR;
>
>
>
>
>
>           PetscInt ii = row - Istart; // array index for d_nnz and o_nnz
>
>
>           if (val!=0 && row >= Istart && row < Iend && col >= Jstart &&
> col < Jend) { d_nnz[ii]++; \
>
> }
>
>
>           if ( (val!=0 && row >= Istart && row < Iend) && (col < Jstart
> || col >= Jend) ) { o_nnz[i\
>
> i]++; }
>
>
>         }
>
>
>       }
>
>
>     }
>
>
>   }
>
>
> }
>
>
>
>
>
>
>
> Thank you,
>
> Yuyun
>
>
>
>
> --
>
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
>
>
> https://www.cse.buffalo.edu/~knepley/
> <http://www.cse.buffalo.edu/~knepley/>
>
>
>
>
> --
>
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
>
>
> https://www.cse.buffalo.edu/~knepley/
> <http://www.cse.buffalo.edu/~knepley/>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221213/44cf9517/attachment-0001.html>


More information about the petsc-users mailing list