Skip to content

Commit ba8781c

Browse files
committed
Avoid calling axpy for small consecutive sums
1 parent 149b89b commit ba8781c

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

highs/ipm/hipo/factorhighs/FactorHiGHSSettings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const double kAlphaBK = 0.01; //(sqrt(17.0) + 1.0) / 8.0;
4444
const Int kBlockGrainSize = 1;
4545
const Int kBlockParallelThreshold = 5;
4646

47+
const Int kMinConsecutiveSums = 10;
48+
4749
// regularisation
4850
const double kDynamicDiagCoeff = 1e-24;
4951

highs/ipm/hipo/factorhighs/Factorise.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void Factorise::processSupernode(Int sn) {
308308
const Int i = S_.relindClique(child_sn, row);
309309

310310
// how many entries to sum
311-
const Int consecutive = S_.consecutiveSums(child_sn, row);
311+
Int consecutive = S_.consecutiveSums(child_sn, row);
312312

313313
FH->assembleFrontalMultiple(consecutive, child_clique, nc, child_sn,
314314
row, col, i, j);

highs/ipm/hipo/factorhighs/FormatHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class FormatHandler {
7575
virtual void initFrontal() = 0;
7676
virtual void initClique() = 0;
7777
virtual void assembleFrontal(Int i, Int j, double val) = 0;
78-
virtual void assembleFrontalMultiple(Int num, const double* child, Int nc,
78+
virtual void assembleFrontalMultiple(Int& num, const double* child, Int nc,
7979
Int child_sn, Int row, Int col, Int i,
8080
Int j) = 0;
8181
virtual void assembleClique(const double* child, Int nc, Int child_sn) = 0;

highs/ipm/hipo/factorhighs/HybridHybridFormatHandler.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void HybridHybridFormatHandler::assembleFrontal(Int i, Int j, double val) {
5555
frontal_[diag_start_[block] + ii + ldb * jj] = val;
5656
}
5757

58-
void HybridHybridFormatHandler::assembleFrontalMultiple(Int num,
58+
void HybridHybridFormatHandler::assembleFrontalMultiple(Int& num,
5959
const double* child,
6060
Int nc, Int child_sn,
6161
Int row, Int col, Int i,
@@ -71,8 +71,14 @@ void HybridHybridFormatHandler::assembleFrontalMultiple(Int num,
7171
Int ii = i - block * nb_;
7272
Int jj = j - block * nb_;
7373

74-
callAndTime_daxpy(num, 1.0, &child[start_block + col_ + jb * row_], jb,
75-
&frontal_[diag_start_[block] + ii + ldb * jj], 1, data_);
74+
if (num > kMinConsecutiveSums)
75+
callAndTime_daxpy(num, 1.0, &child[start_block + col_ + jb * row_], jb,
76+
&frontal_[diag_start_[block] + ii + ldb * jj], 1, data_);
77+
else {
78+
frontal_[diag_start_[block] + ii + ldb * jj] +=
79+
child[start_block + col_ + jb * row_];
80+
num = 1;
81+
}
7682
}
7783

7884
Int HybridHybridFormatHandler::denseFactorise(double reg_thresh) {
@@ -138,7 +144,8 @@ void HybridHybridFormatHandler::assembleClique(const double* child, Int nc,
138144

139145
// sun consecutive entries in a row.
140146
// consecutive need to be reduced, to account for edge of the block
141-
const Int zeros_stored_row = std::max((Int)0, jb_c - (row - row_start) - 1);
147+
const Int zeros_stored_row =
148+
std::max((Int)0, jb_c - (row - row_start) - 1);
142149
Int consecutive = S_->consecutiveSums(child_sn, col);
143150
const Int left_in_child = col_end - col - zeros_stored_row;
144151
consecutive = std::min(consecutive, left_in_child);
@@ -159,11 +166,18 @@ void HybridHybridFormatHandler::assembleClique(const double* child, Int nc,
159166
const Int j_ = j - jblock * nb_;
160167
const Int64 start_block = S_->cliqueBlockStart(sn_, jblock);
161168

162-
callAndTime_daxpy(consecutive, 1.0,
163-
&child[start_block_c + col_ + jb_c * row_], 1,
164-
&clique_ptr_[start_block + j_ + jb * i_], 1, data_);
169+
if (consecutive > kMinConsecutiveSums) {
170+
callAndTime_daxpy(consecutive, 1.0,
171+
&child[start_block_c + col_ + jb_c * row_], 1,
172+
&clique_ptr_[start_block + j_ + jb * i_], 1, data_);
173+
174+
col += consecutive;
175+
} else {
176+
clique_ptr_[start_block + j_ + jb * i_] +=
177+
child[start_block_c + col_ + jb_c * row_];
165178

166-
col += consecutive;
179+
col++;
180+
}
167181
}
168182
}
169183

highs/ipm/hipo/factorhighs/HybridHybridFormatHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class HybridHybridFormatHandler : public FormatHandler {
1313
void initFrontal() override;
1414
void initClique() override;
1515
void assembleFrontal(Int i, Int j, double val) override;
16-
void assembleFrontalMultiple(Int num, const double* child, Int nc,
16+
void assembleFrontalMultiple(Int& num, const double* child, Int nc,
1717
Int child_sn, Int row, Int col, Int i,
1818
Int j) override;
1919
Int denseFactorise(double reg_thresh) override;

0 commit comments

Comments
 (0)