I am running a subgraph counting code on some moderately large graphs as inputs (approximately 160000 nodes). The code I am running involves repeated calling of a method calls MatchSubgraph(). Inside, I have a vector which holds possible candidate nodes which can be matched to a node in the template graph. Each time, I call MatchSubgraph(), I have to initialize the vector candidate (vector<Vertex> candidate) and at the end, I clear it out (candidate.clear()).
Now, once I initialize the vector, after few iterations, which by the work perfectly, when I am trying to put nodes into vector using either insert() or push_back(), it segfaults. On closure scrutiny, I found out that only the fist element gets inserted into the vector, and then the segfault occurs. Note this happens, after 35 iterations. All the previous iterations, things worked fine. I couldn't figure out why.
I understand it is a bit hard to tell without looking at the code.
I have been doing this for few months now and basically, I am teaching myself C++. So any help would be greatly appreciated.
bool SubGraph::MatchSubgraph(Vsize i)
{
Vertex sv = BFSlist[i], u, v; // will find the mapping of sv in this function
cout << "MatchSubgraph("<<i<< "): sv is " << sv << endl;
Byte label = sg.label[sv];
//cout << "MatchSubgraph("<<i<< "): label[sv] is " << label << endl;
Vlist snbr = sg.nlist[sv], nbr, edr;
Vlist sedr = sg.eDir[sv];
//Vlist candidate;
Word *lidx;
Word ncand, csize, k, m, pos; // number of candidates
bool satisfied;
for (k=0; vmap[snbr[k]]==NONE; k++); // find the first matched neighbor of sv
cout << "MatchSubgraph("<<i<<"):first matched ngb of "<< sv << " " << vmap[snbr[k]] <<endl;
// cout << "Ngb of "<< sv << "in the subgph is " << snbr[k] << endl;
u = vmap[snbr[k]]; // u (in g) is matched with neighbor snbr[k] of sv
cout <<"MatchSubgraph("<<i<<"): Note: u = vmap[snbr[k]] "<< u << "is in g " << endl;
nbr = g.nlist[u];
edr = g.eDir[u]; //added
lidx = g.lindex[u];
==============================
The problem occurs in lines marked with PROBLEM LINE in MatchSubgraph() method. There are other methods and a subgraph class (represented by sg) and a graph class (represented by g) which I have deleted for the sake of compactness.
Sorry, but I don't know how to reduce the size of the methods further.
I'm guessing thatnbr[j+lidx[label]] is accessing out of bounds somewhere, try using a debugger to look at the value of j and lidx[label] at that point.