Skip to content

Commit

Permalink
Merge pull request osqp#30 from ali5h/lsolve-perf
Browse files Browse the repository at this point in the history
reduce memory access in linear solve loop
  • Loading branch information
bstellato authored Jul 29, 2020
2 parents 69e845b + ace8c5c commit 7d16b70
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/qdldl.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,12 @@ void QDLDL_Lsolve(const QDLDL_int n,
const QDLDL_float* Lx,
QDLDL_float* x){

QDLDL_int i,j;
QDLDL_int i,j;
for(i = 0; i < n; i++){
for(j = Lp[i]; j < Lp[i+1]; j++){
x[Li[j]] -= Lx[j]*x[i];
}
QDLDL_float val = x[i];
for(j = Lp[i]; j < Lp[i+1]; j++){
x[Li[j]] -= Lx[j]*val;
}
}
}

Expand All @@ -254,11 +255,13 @@ void QDLDL_Ltsolve(const QDLDL_int n,
const QDLDL_float* Lx,
QDLDL_float* x){

QDLDL_int i,j;
QDLDL_int i,j;
for(i = n-1; i>=0; i--){
for(j = Lp[i]; j < Lp[i+1]; j++){
x[i] -= Lx[j]*x[Li[j]];
}
QDLDL_float val = x[i];
for(j = Lp[i]; j < Lp[i+1]; j++){
val -= Lx[j]*x[Li[j]];
}
x[i] = val;
}
}

Expand All @@ -270,10 +273,9 @@ void QDLDL_solve(const QDLDL_int n,
const QDLDL_float* Dinv,
QDLDL_float* x){

QDLDL_int i;

QDLDL_Lsolve(n,Lp,Li,Lx,x);
for(i = 0; i < n; i++) x[i] *= Dinv[i];
QDLDL_Ltsolve(n,Lp,Li,Lx,x);
QDLDL_int i;

QDLDL_Lsolve(n,Lp,Li,Lx,x);
for(i = 0; i < n; i++) x[i] *= Dinv[i];
QDLDL_Ltsolve(n,Lp,Li,Lx,x);
}

0 comments on commit 7d16b70

Please sign in to comment.