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

Faster bands: do set_blas_threads(1) before diagonalization, then restore #226

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

pablosanjose
Copy link
Owner

@pablosanjose pablosanjose commented Nov 10, 2023

The diagonalization step in bands is multithreaded over momenta. BLAS is also multithreaded by default. But actual diagonalization of matrices is more difficult to multithread than the loop over momenta, so it is much faster to switch to 1 single BLAS thread for the diagonalization step in bands, and then return to whatever it was before. The difference is specially dramatic using EigenSolvers.LinearAlgebra, to the point in which it is the fastest method (with multithreading) up to pretty large unit cells (like here, with 200 orbitals, 8 threads)

Master:

~ julia -t 8 -e "using Quantica, LinearAlgebra; h = HP.graphene() |> supercell(10); s=subdiv(0,2pi,50); @time bands(h, s, s);"
Step 1 - Diagonalizing: 100%|██████████████████████████████████| Time: 0:01:55
Step 2 - Knitting: 100%|███████████████████████████████████████| Time: 0:00:06
126.732104 seconds (26.83 M allocations: 11.157 GiB, 0.36% gc time, 4.15% compilation time)

This PR:

~ julia -t 8 -e "using Quantica, LinearAlgebra; h = HP.graphene() |> supercell(10); s=subdiv(0,2pi,50); @time bands(h, s, s);"
Step 1 - Diagonalizing: 100%|██████████████████████████████████| Time: 0:00:04
Step 2 - Knitting: 100%|███████████████████████████████████████| Time: 0:00:05
 15.468912 seconds (26.88 M allocations: 11.161 GiB, 3.01% gc time, 39.75% compilation time)

@codecov-commenter
Copy link

codecov-commenter commented Nov 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (333ffd8) 92.59% compared to head (97d84d0) 92.60%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #226   +/-   ##
=======================================
  Coverage   92.59%   92.60%           
=======================================
  Files          34       34           
  Lines        5457     5460    +3     
=======================================
+ Hits         5053     5056    +3     
  Misses        404      404           
Files Coverage Δ
src/bands.jl 97.68% <100.00%> (+0.01%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pablosanjose pablosanjose changed the title Do set_blas_threads(1) to diagonalize, then restore Faster bands: do set_blas_threads(1) before diagonalization, then restore Nov 10, 2023
@pablosanjose pablosanjose merged commit 0f4bc9c into master Nov 10, 2023
8 checks passed
pablosanjose added a commit that referenced this pull request Nov 10, 2023
@pablosanjose pablosanjose deleted the blasthreads branch January 23, 2024 07:18
@pablosanjose pablosanjose mentioned this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants