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

Matthew Knepley knepley at gmail.com
Mon Dec 12 22:41:07 CST 2022


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/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221212/ea1539aa/attachment-0001.html>


More information about the petsc-users mailing list