Unverified Commit 27e0e547 authored by Quan (Andy) Gan's avatar Quan (Andy) Gan Committed by GitHub
Browse files

[BUG] Graceful handling of random walking with no successors (#433)

parent d3c24cc2
...@@ -504,12 +504,9 @@ IdArray SamplerOp::RandomWalk( ...@@ -504,12 +504,9 @@ IdArray SamplerOp::RandomWalk(
DLContext{kDLCPU, 0}); DLContext{kDLCPU, 0});
dgl_id_t *trace_data = static_cast<dgl_id_t *>(traces->data); dgl_id_t *trace_data = static_cast<dgl_id_t *>(traces->data);
#pragma omp parallel // FIXME: does OpenMP work with exceptions? Especially without throwing SIGABRT?
{ unsigned int random_seed = time(nullptr);
// get per-thread seed
unsigned int random_seed = time(nullptr) ^ omp_get_thread_num();
#pragma omp for
for (int i = 0; i < num_nodes; ++i) { for (int i = 0; i < num_nodes; ++i) {
const dgl_id_t seed_id = seed_ids[i]; const dgl_id_t seed_id = seed_ids[i];
...@@ -523,8 +520,11 @@ IdArray SamplerOp::RandomWalk( ...@@ -523,8 +520,11 @@ IdArray SamplerOp::RandomWalk(
const auto succ = gptr->SuccVec(cur); const auto succ = gptr->SuccVec(cur);
const size_t size = succ.size(); const size_t size = succ.size();
cur = succ[rand_r(&random_seed) % size]; if (size == 0) {
LOG(FATAL) << "no successors from vertex " << cur;
return traces;
} }
cur = succ[rand_r(&random_seed) % size];
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment