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

Change DFTK thread count to a runtime setting #1028

Merged
merged 5 commits into from
Dec 5, 2024

Conversation

Technici4n
Copy link
Contributor

Fixes #1012 by changing the number of DFTK threads to a runtime setting.

Do we care about potential races when calling set_DFTK_threads!() in parallel? I suppose not. I don't want to make it an atomic.

"""
function disable_threading()
setup_threading(;n_fft=1, n_blas=1, n_DFTK=1)
end

# TODO: is a single write to an Int64 atomic?
DFTK_threads = 0
Copy link
Member

Choose a reason for hiding this comment

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

Should be const for sure.

But also this is global state. Do we really want this?

Copy link
Member

Choose a reason for hiding this comment

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

Apparently according to Valentin the way to go is https://github.com/vchuravy/ScopedValues.jl, which will become part of base in 1.11. Can you look into this ?

Copy link
Contributor Author

@Technici4n Technici4n Nov 27, 2024

Choose a reason for hiding this comment

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

Funny how that's actually inspired from a Java API. 😄

I'm not sure that

with(DFTK_THREADS => 1) do
    # All computations here
end

is very user friendly however, especially since it's inconsistent with BLAS and FFTW threads.

It's not REPL-friendly either.

Copy link
Contributor Author

@Technici4n Technici4n Nov 27, 2024

Choose a reason for hiding this comment

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

Making it const is a bad idea, the point is that it's actually mutable (and will be mutated by set_DFTK_threads!):

WARNING: redefinition of constant DFTK.DFTK_threads. This may fail, cause incorrect answers, or produce other errors.

Copy link
Member

Choose a reason for hiding this comment

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

const does not mean that it's immutable if you make it a Ref. It most importantly it ensures the type does not change.

also with(DFTK_THREADS => 1) do can be wrapped.

Copy link
Contributor Author

@Technici4n Technici4n Nov 28, 2024

Choose a reason for hiding this comment

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

I talked to Valentin again, and the ideal thing to do would be to split work based on statically known block sizes (wherever we call parallel_loop_over_range at least), and let the Julia scheduler handle this. However I don't want to do this now.

@mfherbst
Copy link
Member

mfherbst commented Dec 5, 2024

Ok, let's do it like this for now. We should really revisit our HPC setup and scheduling (like have some proper structured way of configuring this).

@mfherbst mfherbst enabled auto-merge (squash) December 5, 2024 14:50
@mfherbst mfherbst merged commit 12f829d into JuliaMolSim:master Dec 5, 2024
7 of 8 checks passed
@Technici4n Technici4n deleted the revert-threading-preference branch December 5, 2024 21:13
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.

Setting a >1 threading preference will trigger a recompilation and make it fail
2 participants