[petsc-users] Seg fault in gdb but program runs
Yuyun Yang
yyang85 at alumni.stanford.edu
Mon Dec 12 20:56:18 CST 2022
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? 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:
// 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221213/c5e88c75/attachment-0001.html>
More information about the petsc-users
mailing list