Skip to content

Commit fb1d541

Browse files
committed
Switch off tree parallelism if depth of recursion is too large
1 parent 70d71d5 commit fb1d541

7 files changed

Lines changed: 30 additions & 1 deletion

File tree

highs/ipm/hipo/auxiliary/Auxiliary.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ Int64 getDiagStart(Int n, Int k, Int nb, Int n_blocks,
208208
return result;
209209
}
210210

211+
Int maxDepthTree(const std::vector<Int>& parent) {
212+
Int max_depth = 0;
213+
std::vector<Int> depth(parent.size(), -1);
214+
for (Int i = 0; i < parent.size(); ++i) {
215+
Int node = i;
216+
Int value = 1;
217+
while (node != -1) {
218+
if (value > depth[node]) {
219+
depth[node] = value;
220+
} else
221+
break;
222+
223+
++value;
224+
node = parent[node];
225+
}
226+
if (parent[i] == -1) max_depth = std::max(max_depth, depth[i]);
227+
}
228+
return max_depth;
229+
}
230+
211231
Clock::Clock() { start(); }
212232
void Clock::start() { t0 = std::chrono::high_resolution_clock::now(); }
213233
double Clock::stop() const {

highs/ipm/hipo/auxiliary/Auxiliary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void processEdge(Int j, Int i, const std::vector<Int>& first,
2828
std::vector<Int>& prevleaf, std::vector<Int>& ancestor);
2929
Int64 getDiagStart(Int n, Int k, Int nb, Int n_blocks,
3030
std::vector<Int64>& start, bool triang = false);
31+
Int maxDepthTree(const std::vector<Int>& parent);
3132

3233
template <typename T>
3334
void counts2Ptr(std::vector<T>& ptr, std::vector<T>& w) {

highs/ipm/hipo/factorhighs/Analyse.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,7 @@ Int Analyse::run(Symbolic& S) {
13491349
S.block_size_ = nb_;
13501350
S.max_stack_size_ = max_stack_size_;
13511351
S.ordering = ordering_;
1352+
S.tree_depth_ = maxDepthTree(sn_parent_);
13521353

13531354
// compute largest supernode
13541355
std::vector<Int> sn_size(sn_start_.begin() + 1, sn_start_.end());

highs/ipm/hipo/factorhighs/Symbolic.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Int64 Symbolic::maxStackSize() const { return max_stack_size_; }
4141
bool Symbolic::parTree() const { return parallel_tree_; }
4242
bool Symbolic::parNode() const { return parallel_node_; }
4343
double Symbolic::storage() const { return serial_storage_; }
44+
Int Symbolic::depth() const { return tree_depth_; }
4445

4546
const std::vector<Int64>& Symbolic::ptr() const { return ptr_; }
4647
const std::vector<Int>& Symbolic::iperm() const { return iperm_; }
@@ -78,6 +79,7 @@ void Symbolic::print(const Log& log, bool verbose) const {
7879
log_stream << textline("Critical ops:") << sci(critops_, 0, 1) << '\n';
7980
log_stream << textline("Max tree speedup:") << fix(flops_ / critops_, 0, 2)
8081
<< '\n';
82+
log_stream << textline("Tree depth:") << integer(tree_depth_, 0) << '\n';
8183
log_stream << textline("Artificial nz:") << sci(artificial_nz_, 0, 1)
8284
<< '\n';
8385
log_stream << textline("Artificial ops:") << sci(artificial_ops_, 0, 1)

highs/ipm/hipo/factorhighs/Symbolic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Symbolic {
9696
std::vector<std::vector<Int64>> clique_block_start_{};
9797

9898
Int64 max_stack_size_{};
99-
99+
Int tree_depth_{};
100100
std::string ordering;
101101

102102
friend class Analyse;
@@ -124,6 +124,7 @@ class Symbolic {
124124
Int64 cliqueBlockStart(Int sn, Int bl) const;
125125
Int64 cliqueSize(Int sn) const;
126126
Int64 maxStackSize() const;
127+
Int depth() const;
127128
bool parTree() const;
128129
bool parNode() const;
129130
double storage() const;

highs/ipm/hipo/ipm/FactorHiGHSSolver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ void FactorHiGHSSolver::setParallel() {
711711
parallel_tree = false;
712712
}
713713

714+
// switch off tree parallelism if depth of recursion is too large
715+
if (S_.depth() > kMaxTreeDepth) parallel_tree = false;
716+
714717
if (parallel_tree && parallel_node) {
715718
options_.parallel = kOptionParallelOn;
716719
log_stream << "Full preferred\n";

highs/ipm/hipo/ipm/Parameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const double kSmallSnThresh = 3.0;
3434
const Int kMinNumberSn = 10;
3535
const double kLargeStorageGB = 20.0;
3636
const double kLargeFillin = 50.0;
37+
const double kMaxTreeDepth = 1000;
3738

3839
// parameters for choice of ordering
3940
const double kFlopsOrderingThresh = 1.2;

0 commit comments

Comments
 (0)