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

Add Conjugate Gradient example to benchmarks #1599

Merged
merged 1 commit into from
Sep 21, 2016
Merged

Add Conjugate Gradient example to benchmarks #1599

merged 1 commit into from
Sep 21, 2016

Conversation

shehzan10
Copy link
Member

Compare the performance and memory usage of sparse vs dense using conjugate
gradient example

[skip arrayfire ci]

@shehzan10 shehzan10 added this to the v3.4.1 milestone Sep 20, 2016
Copy link
Member

@umar456 umar456 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor changes.


static array A;
static array spA; // Sparse A
static array x0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks too similar to a hex number.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x0 is a mathematical notation used in conjugate gradient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shehzan10 FYI, try to use X0 in such cases.

array r = b - matmul(A, x);
array p = r;

for (int i = 0; i < maxIter; ++i) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't the timeit function execute this multiple times anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not for timing, conjugate gradient is an iterative solver.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I don't know what I was thinking.

x = x + tile(alpha, Ap.dims())*p;
array beta_num = dot(r, r);
array beta = beta_num/alpha_num;
p = r + tile(beta, p.dims())*p;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p *= r + tile(beta, p.dims());

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@umar456 These expressions are not equivalent. We want something like this p = r + scalar*p.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doh! Clearly its time for bed.

array alpha_den = dot(p, Ap);
array alpha = alpha_num/alpha_den;
r = r - tile(alpha, Ap.dims())*Ap;
x = x + tile(alpha, Ap.dims())*p;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x += tile(alpha, Ap.dims())*p;

array alpha_num = dot(r, r);
array alpha_den = dot(p, Ap);
array alpha = alpha_num/alpha_den;
r = r - tile(alpha, Ap.dims())*Ap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r -= tile(alpha, Ap.dims())*Ap;

Compare the performance and memory usage of sparse vs dense using conjugate
gradient example
@shehzan10 shehzan10 merged commit 72ff8dd into arrayfire:hotfix-3.4.1 Sep 21, 2016
@shehzan10 shehzan10 deleted the cg_example branch September 21, 2016 14:54
@shehzan10 shehzan10 mentioned this pull request Oct 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants