diff --git a/src/caffe/parallel.cpp b/src/caffe/parallel.cpp index 34ad49edf8a..5d5e43a97d7 100644 --- a/src/caffe/parallel.cpp +++ b/src/caffe/parallel.cpp @@ -185,9 +185,8 @@ void DevicePair::compute(const vector devices, vector* pairs) { DLOG(INFO) << "GPUs paired by P2P access, remaining: " << s.str(); // Group remaining - remaining_depth = ceil(log2(remaining.size())); - for (int d = 0; d < remaining_depth; ++d) { - for (int i = 0; i < remaining.size(); ++i) { + while (remaining.size() > 1) { + for (int i = 0; i+1 < remaining.size(); ++i) { pairs->push_back(DevicePair(remaining[i], remaining[i + 1])); DLOG(INFO) << "Remaining pair: " << remaining[i] << ":" << remaining[i + 1];