I am trying to implement BFS algorithm using GraphLab. In my vertex_data struct I am using a vector to hold the path that has been traversed so far.
struct vertex_data {
std::vector<int> current_path;
bool visited;
int destination;
vertex_data() {
destination = -1;
visited = false;
}
}
Then in the apply() function I am trying to push the current vertex id to the current_path of that particular vertex:
class bfs: public graphlab::ivertex_program<graph_type, graphlab::empty,
vertex_data> {
private:
vertex_data msg;
public:
void apply(icontext_type& context, vertex_type& vertex, const gather_type& gather_result) {
int vid = vertex.id();
vertex.data().destination = msg.destination;
vertex.data().visited = true;
msg.current_path.push_back(vid);
vertex.data().current_path.push_back(vid);
}
}
Also the definition of data() in the documentation is:
vertex_data_type & data ()
Returns a reference to the data on the vertex.
GraphLab is taking care of wrapping the vertex_data object as vertex_data_type. When I run it, I get seg fault in the push_back() function for some vertices. I have checked vid and it is always an integer with an actual value. Running vertex.data().current_path.size(), I get 0.
I have tried several approaches like creating a local vector and replacing the one at vertex.data() and resizing before pushing the id. In the first case I get the seg fault when trying to replace and in the second case resize gets executed without problems but the push keeps giving me seg fault.
Do you have any ideas of what might be the problem?
Thanks