Skip to content

Commit 131ce3e

Browse files
committed
sn_columns is now allocated only once and reused, quite ugly for now
1 parent 2b8512a commit 131ce3e

File tree

11 files changed

+40
-30
lines changed

11 files changed

+40
-30
lines changed

highs/ipm/hipo/factorhighs/FactorHiGHS.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ Int FHsolver::factorise(Numeric& N, const Symbolic& S,
4545
const std::vector<Int>& rows,
4646
const std::vector<Int>& ptr,
4747
const std::vector<double>& vals) {
48+
if (sn_columns_.empty()) {
49+
sn_columns_.resize(S.sn());
50+
printf("Resizing\n");
51+
}
52+
4853
Factorise fact_obj(S, rows, ptr, vals, regul_, log_, data_, sn_columns_);
4954
return fact_obj.run(N);
5055
}
5156

57+
std::vector<std::vector<double>>& FHsolver::columns() { return sn_columns_; }
58+
5259
} // namespace hipo

highs/ipm/hipo/factorhighs/FactorHiGHS.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class FHsolver {
9999
// Set values for static regularisation to be added when a pivot is selected.
100100
// If regularisation is already added to the matrix, ignore.
101101
void setRegularisation(double reg_p, double reg_d);
102+
103+
std::vector<std::vector<double>>& columns();
102104
};
103105

104106
/* To do

highs/ipm/hipo/factorhighs/Factorise.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void Factorise::processSupernode(Int sn) {
201201
// initialise the format handler
202202
// this also allocates space for the frontal matrix and schur complement
203203
std::unique_ptr<FormatHandler> FH(
204-
new HybridHybridFormatHandler(S_, sn, regul_, data_));
204+
new HybridHybridFormatHandler(S_, sn, regul_, data_, sn_columns_[sn]));
205205

206206
#if HIPO_TIMING_LEVEL >= 2
207207
data_.sumTime(kTimeFactorisePrepare, clock.stop());
@@ -344,8 +344,8 @@ void Factorise::processSupernode(Int sn) {
344344
FH->extremeEntries();
345345

346346
// terminate the format handler
347-
FH->terminate(sn_columns_[sn], schur_contribution_[sn], total_reg_,
348-
swaps_[sn], pivot_2x2_[sn]);
347+
FH->terminate(schur_contribution_[sn], total_reg_, swaps_[sn],
348+
pivot_2x2_[sn]);
349349
#if HIPO_TIMING_LEVEL >= 2
350350
data_.sumTime(kTimeFactoriseTerminate, clock.stop());
351351
#endif
@@ -360,7 +360,7 @@ bool Factorise::run(Numeric& num) {
360360

361361
// allocate space for list of generated elements and columns of L
362362
schur_contribution_.resize(S_.sn());
363-
sn_columns_.resize(S_.sn());
363+
// sn_columns_.resize(S_.sn());
364364
swaps_.resize(S_.sn());
365365
pivot_2x2_.resize(S_.sn());
366366

@@ -388,7 +388,6 @@ bool Factorise::run(Numeric& num) {
388388
if (flag_stop_) return true;
389389

390390
// move factorisation to numerical object
391-
num.sn_columns_ = std::move(sn_columns_);
392391
num.total_reg_ = std::move(total_reg_);
393392
num.swaps_ = std::move(swaps_);
394393
num.pivot_2x2_ = std::move(pivot_2x2_);

highs/ipm/hipo/factorhighs/FormatHandler.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66

77
namespace hipo {
88

9-
FormatHandler::FormatHandler(const Symbolic& S, Int sn, const Regul& regul)
9+
FormatHandler::FormatHandler(const Symbolic& S, Int sn, const Regul& regul,
10+
std::vector<double>& frontal)
1011
: S_{&S},
1112
regul_{regul},
1213
sn_{sn},
1314
nb_{S_->blockSize()},
1415
sn_size_{S_->snStart(sn_ + 1) - S_->snStart(sn_)},
1516
ldf_{S_->ptr(sn_ + 1) - S_->ptr(sn_)},
16-
ldc_{ldf_ - sn_size_} {
17+
ldc_{ldf_ - sn_size_},
18+
frontal_{frontal} {
1719
local_reg_.resize(sn_size_);
1820
swaps_.resize(sn_size_);
1921
pivot_2x2_.resize(sn_size_);
2022
}
2123

22-
void FormatHandler::terminate(std::vector<double>& frontal,
23-
std::vector<double>& clique,
24+
void FormatHandler::terminate(std::vector<double>& clique,
2425
std::vector<double>& total_reg,
2526
std::vector<Int>& swaps,
2627
std::vector<double>& pivot_2x2) {
@@ -29,7 +30,6 @@ void FormatHandler::terminate(std::vector<double>& frontal,
2930
// accessed only here, while a local copy is used for the assembly and dense
3031
// factorisation. This should avoid the problem of false sharing.
3132

32-
frontal = std::move(frontal_);
3333
clique = std::move(clique_);
3434
swaps = std::move(swaps_);
3535
pivot_2x2 = std::move(pivot_2x2_);

highs/ipm/hipo/factorhighs/FormatHandler.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ class FormatHandler {
4848
const Int ldc_{};
4949

5050
// local copies to be moved at the end
51-
std::vector<double> frontal_{};
51+
std::vector<double>& frontal_;
5252
std::vector<double> clique_{};
5353
std::vector<double> local_reg_{};
5454
std::vector<Int> swaps_{};
5555
std::vector<double> pivot_2x2_{};
5656

5757
public:
58-
FormatHandler(const Symbolic& S, Int sn, const Regul& regul);
59-
void terminate(std::vector<double>& frontal, std::vector<double>& clique,
60-
std::vector<double>& total_reg, std::vector<Int>& swaps,
61-
std::vector<double>& pivot_2x2);
58+
FormatHandler(const Symbolic& S, Int sn, const Regul& regul,
59+
std::vector<double>& frontal);
60+
void terminate(std::vector<double>& clique, std::vector<double>& total_reg,
61+
std::vector<Int>& swaps, std::vector<double>& pivot_2x2);
6262

6363
// avoid copies
6464
FormatHandler(const FormatHandler&) = delete;

highs/ipm/hipo/factorhighs/HybridHybridFormatHandler.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
namespace hipo {
99

10-
HybridHybridFormatHandler::HybridHybridFormatHandler(const Symbolic& S, Int sn,
11-
const Regul& regul,
12-
DataCollector& data)
13-
: FormatHandler(S, sn, regul), data_{data} {
10+
HybridHybridFormatHandler::HybridHybridFormatHandler(
11+
const Symbolic& S, Int sn, const Regul& regul, DataCollector& data,
12+
std::vector<double>& frontal)
13+
: FormatHandler(S, sn, regul, frontal), data_{data} {
1414
// initialise frontal and clique
1515
initFrontal();
1616
initClique();
@@ -20,7 +20,7 @@ void HybridHybridFormatHandler::initFrontal() {
2020
const Int n_blocks = (sn_size_ - 1) / nb_ + 1;
2121
diag_start_.resize(n_blocks);
2222
Int frontal_size = getDiagStart(ldf_, sn_size_, nb_, n_blocks, diag_start_);
23-
frontal_.resize(frontal_size + extra_space);
23+
frontal_.assign(frontal_size + extra_space, 0.0);
2424
// NB: the plus 10 is not needed, but it avoids weird problems later on.
2525
}
2626

highs/ipm/hipo/factorhighs/HybridHybridFormatHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class HybridHybridFormatHandler : public FormatHandler {
2323

2424
public:
2525
HybridHybridFormatHandler(const Symbolic& S, Int sn, const Regul& regul,
26-
DataCollector& data);
26+
DataCollector& data, std::vector<double>& frontal);
2727
};
2828

2929
} // namespace hipo

highs/ipm/hipo/factorhighs/Numeric.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
namespace hipo {
1414

15-
Numeric::Numeric(const Symbolic& S) : S_{S} {
15+
Numeric::Numeric(const Symbolic& S,
16+
std::vector<std::vector<double>>& sn_columns)
17+
: S_{S}, sn_columns_{sn_columns} {
1618
// initialise solve handler
1719
SH_.reset(new HybridSolveHandler(S_, sn_columns_, swaps_, pivot_2x2_));
1820
}

highs/ipm/hipo/factorhighs/Numeric.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace hipo {
1313

1414
class Numeric {
1515
// columns of factorisation, stored by supernode
16-
std::vector<std::vector<double>> sn_columns_{};
16+
const std::vector<std::vector<double>>& sn_columns_;
1717

1818
// swaps of columns for each supernode, ordered locally within a block
1919
std::vector<std::vector<Int>> swaps_{};
@@ -43,7 +43,7 @@ class Numeric {
4343
// dynamic regularisation applied to the matrix
4444
std::vector<double> total_reg_{};
4545

46-
Numeric(const Symbolic& S);
46+
Numeric(const Symbolic& S, std::vector<std::vector<double>>& sn_columns);
4747

4848
// Full solve with refinement
4949
// Return pair (number of solves, final residual)

highs/ipm/hipo/ipm/FactorHiGHSSolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace hipo {
1111
FactorHiGHSSolver::FactorHiGHSSolver(Options& options, const Model& model,
1212
const Regularisation& regul, Info* info,
1313
IpmData* record, const LogHighs& log)
14-
: S_{},
15-
N_(S_),
16-
FH_(&log, options.block_size),
14+
: FH_(&log, options.block_size),
15+
S_{},
16+
N_(S_, FH_.columns()),
1717
regul_{regul},
1818
info_{info},
1919
data_{record},

0 commit comments

Comments
 (0)