Skip to content

Commit e6160c8

Browse files
committed
Partial sovles with multiple rhs
1 parent 709e4ac commit e6160c8

6 files changed

Lines changed: 49 additions & 33 deletions

File tree

highs/ipm/hipo/factorhighs/FactorHighs.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ Int FHsolver::factorise(const Symbolic& S, Int n, Int nz, const Int* rows,
3838
}
3939

4040
Int FHsolver::solve(double* x, Int k) const { return N_.solve(x, k); }
41-
Int FHsolver::forwardSolve(double* x) const { return N_.forwardSolve(x); }
42-
Int FHsolver::diagSolve(double* x) const { return N_.diagSolve(x); }
43-
Int FHsolver::backwardSolve(double* x) const { return N_.backwardSolve(x); }
41+
Int FHsolver::forwardSolve(double* x, Int k) const {
42+
return N_.forwardSolve(x, k);
43+
}
44+
Int FHsolver::diagSolve(double* x, Int k) const { return N_.diagSolve(x, k); }
45+
Int FHsolver::backwardSolve(double* x, Int k) const {
46+
return N_.backwardSolve(x, k);
47+
}
4448

4549
void FHsolver::getRegularisation(double* reg) { N_.getReg(reg); }
4650

highs/ipm/hipo/factorhighs/FactorHighs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ class FHsolver {
103103
Int solve(double* x, Int k = 1) const;
104104

105105
// Perform partial solves with L, D, L^T (including permutation)
106-
Int forwardSolve(double* x) const;
107-
Int diagSolve(double* x) const;
108-
Int backwardSolve(double* x) const;
106+
Int forwardSolve(double* x, Int k = 1) const;
107+
Int diagSolve(double* x, Int k = 1) const;
108+
Int backwardSolve(double* x, Int k = 1) const;
109109

110110
// If multiple factorisation are performed, call newIter() before each
111111
// factorisation. This is used only to collect data for debugging, if

highs/ipm/hipo/factorhighs/FactorHighs_c_api.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ HighsInt FactorHighs_solve(void* FH, double* x, HighsInt k) {
3535
return ((hipo::FHsolver*)FH)->solve(x, k);
3636
}
3737

38-
HighsInt FactorHighs_forwardSolve(void* FH, double* x) {
39-
return ((hipo::FHsolver*)FH)->forwardSolve(x);
38+
HighsInt FactorHighs_forwardSolve(void* FH, double* x, HighsInt k) {
39+
return ((hipo::FHsolver*)FH)->forwardSolve(x, k);
4040
}
4141

42-
HighsInt FactorHighs_diagSolve(void* FH, double* x) {
43-
return ((hipo::FHsolver*)FH)->diagSolve(x);
42+
HighsInt FactorHighs_diagSolve(void* FH, double* x, HighsInt k) {
43+
return ((hipo::FHsolver*)FH)->diagSolve(x, k);
4444
}
4545

46-
HighsInt FactorHighs_backwardSolve(void* FH, double* x) {
47-
return ((hipo::FHsolver*)FH)->backwardSolve(x);
46+
HighsInt FactorHighs_backwardSolve(void* FH, double* x, HighsInt k) {
47+
return ((hipo::FHsolver*)FH)->backwardSolve(x, k);
4848
}
4949

5050
void FactorHighs_setRegularisation(void* FH, double reg_p, double reg_d) {

highs/ipm/hipo/factorhighs/FactorHighs_c_api.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ HighsInt FactorHighs_factorise(void* FH, const void* S, HighsInt n, HighsInt nz,
3131
HighsInt FactorHighs_solve(void* FH, double* x, HighsInt k);
3232

3333
// Partial solves
34-
HighsInt FactorHighs_forwardSolve(void* FH, double* x);
35-
HighsInt FactorHighs_diagSolve(void* FH, double* x);
36-
HighsInt FactorHighs_backwardSolve(void* FH, double* x);
34+
HighsInt FactorHighs_forwardSolve(void* FH, double* x, HighsInt k);
35+
HighsInt FactorHighs_diagSolve(void* FH, double* x, HighsInt k);
36+
HighsInt FactorHighs_backwardSolve(void* FH, double* x, HighsInt k);
3737

3838
// Reordering
3939
HighsInt FactorHighs_reorderMetis(void* FH, HighsInt n, HighsInt nz,

highs/ipm/hipo/factorhighs/Numeric.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,6 @@ Int Numeric::solve(double* x) const {
4444
return kRetOk;
4545
}
4646

47-
Int Numeric::solve(double* x, Int k) const {
48-
if (k == 1)
49-
return solve(x);
50-
else {
51-
highs::parallel::TaskGroup tg;
52-
const Int n = S_->size();
53-
std::atomic<bool> fail{false};
54-
for (Int i = 0; i < k; ++i) {
55-
tg.spawn([=, &fail]() {
56-
Int status = solve(&x[i * n]);
57-
if (status) fail.store(true, std::memory_order_relaxed);
58-
});
59-
}
60-
tg.taskWait();
61-
return fail;
62-
}
63-
}
64-
6547
Int Numeric::forwardSolve(double* x) const {
6648
if (!sn_columns_ || !S_ || !data_ || !options_) return kRetInvalidPointer;
6749
HybridSolveHandler SH(*S_, *sn_columns_, swaps_, pivot_2x2_, *data_,
@@ -86,6 +68,32 @@ Int Numeric::backwardSolve(double* x) const {
8668
return kRetOk;
8769
}
8870

71+
#define SOLVE_MULTIPLE(f) \
72+
if (k == 1) \
73+
return f(x); \
74+
else { \
75+
highs::parallel::TaskGroup tg; \
76+
const Int n = S_->size(); \
77+
std::atomic<bool> fail{false}; \
78+
for (Int i = 0; i < k; ++i) { \
79+
tg.spawn([=, &fail]() { \
80+
Int status = f(&x[i * n]); \
81+
if (status) fail.store(true, std::memory_order_relaxed); \
82+
}); \
83+
} \
84+
tg.taskWait(); \
85+
return fail; \
86+
}
87+
88+
Int Numeric::solve(double* x, Int k) const { SOLVE_MULTIPLE(solve); }
89+
Int Numeric::forwardSolve(double* x, Int k) const {
90+
SOLVE_MULTIPLE(forwardSolve);
91+
}
92+
Int Numeric::diagSolve(double* x, Int k) const { SOLVE_MULTIPLE(diagSolve); }
93+
Int Numeric::backwardSolve(double* x, Int k) const {
94+
SOLVE_MULTIPLE(backwardSolve);
95+
}
96+
8997
void Numeric::getReg(double* reg) {
9098
std::memcpy(reg, total_reg_.data(), total_reg_.size() * sizeof(double));
9199
}

highs/ipm/hipo/factorhighs/Numeric.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class Numeric {
4646
Int diagSolve(double* x) const;
4747
Int backwardSolve(double* x) const;
4848

49+
Int forwardSolve(double* x, Int k) const;
50+
Int diagSolve(double* x, Int k) const;
51+
Int backwardSolve(double* x, Int k) const;
52+
4953
void getReg(double* reg);
5054
void inertia(Int& pos, Int& neg, Int& zero, double tol) const;
5155
};

0 commit comments

Comments
 (0)