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

Use math expression to enhance performance #30

Merged
merged 5 commits into from
Sep 4, 2024
Merged

Use math expression to enhance performance #30

merged 5 commits into from
Sep 4, 2024

Conversation

huiyuxie
Copy link
Member

@huiyuxie huiyuxie commented Sep 4, 2024

Current implementation rely on function isequal to avoid control flow divergence. The benchmarks showed that this function can be replaced by math expression to enhance the performance.

For example,

# `side` equals either 1 or 2
boundaries_u[1, j, k] = u[j, size(u, 2), element] * isequal(side, 1) # check if `side` equals 1
boundaries_u[2, j, k] = u[j, 1, element] * isequal(side, 2) # check if `side` equals 2

can be easily replaced by

# `side` equals either 1 or 2
boundaries_u[1, j, k] = u[j, size(u, 2), element] * (2 - side) 
boundaries_u[2, j, k] = u[j, 1, element] * (side - 1) 

This also applies to other similar situations.

@huiyuxie huiyuxie added the performance Improve performance label Sep 4, 2024
@huiyuxie
Copy link
Member Author

huiyuxie commented Sep 4, 2024

Address part of #22

@huiyuxie
Copy link
Member Author

huiyuxie commented Sep 4, 2024

The isequal performs better in 3D case but remains a little bit worse than math expression in 1D and 2D cases. So here we use hybrid of isequal function and math expression.

@huiyuxie huiyuxie merged commit 49e25fb into main Sep 4, 2024
6 checks passed
@huiyuxie huiyuxie deleted the math branch September 4, 2024 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Improve performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant