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

API Request: number of processors (including threads) #474

Closed
schlichtanders opened this issue Mar 4, 2024 · 1 comment · Fixed by #500
Closed

API Request: number of processors (including threads) #474

schlichtanders opened this issue Mar 4, 2024 · 1 comment · Fixed by #500

Comments

@schlichtanders
Copy link

I saw that shard is able to compute the number of processors, optionally also including threads.

Dagger.jl/src/chunks.jl

Lines 176 to 198 in cec17a1

function shard(@nospecialize(f); procs=nothing, workers=nothing, per_thread=false)
if procs === nothing
if workers !== nothing
procs = [OSProc(w) for w in workers]
else
procs = lock(Sch.eager_context()) do
copy(Sch.eager_context().procs)
end
end
if per_thread
_procs = ThreadProc[]
for p in procs
append!(_procs, filter(p->p isa ThreadProc, get_processors(p)))
end
procs = _procs
end
else
if workers !== nothing
throw(ArgumentError("Cannot combine `procs` and `workers`"))
elseif per_thread
throw(ArgumentError("Cannot combine `procs` and `per_thread=true`"))
end
end

It would be great if this could be available via an API like Dagger.nprocs

@jpsamaroo
Copy link
Member

We now have Dagger.all_processors() and Dagger.compatible_processors(scope::Dagger.AbstractScope) for getting the set of processors, and so we could implement a Dagger.num_processors() that does what you ask. I would avoid overloading nprocs, since Distributed exports that as well (and we use it in Dagger internally).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants