Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce memory access in linear solve loop #30

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}