You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a use case where we would like to dask.distributed to parallelize a python-bound C++ program that would work best if it could consume 8-32 threads depending on the problem size and will manage threading internally. Normally, a Dask worker is run on a node that has 32 cores with the worker using 2 processes at 1 thread each so that we can give each process 16 cores.
Looking at the code currently, it seems that nthreads = ncores / nprocesses without exceptions, is there a canonical way to change this so that we can orchestrate our normal Dask worker operation with dask-jobqueue?
Reacted by Daniel Farrell, Daniel Smith, David Slochower, Greg M. Fleishman and Mateusz Bieniek
Funnily enough, I think we just had a conversation on this point in #179.
As you point out cores/processes kwargs are used both to configure dask-worker command, and to reserve jobqueue system resources. However, the second part is just by default guessed from this kwargs. In every JobQueueCluster implementation, there should be another kwarg allowing you to force different resource reservation on the underlying scheduling system. For example with PBSCluster:
saw on LSF you could select cpus, but I wasn't aware of the PBSCluster abilities to write out resource specs. To make things simpler, would it be possible to set the number of threads manually so that you would have nthreads = None which would default to current behavior.
It is worth considering this in a larger context where one might wish to start heterogeneous workers with labels where expanding def start_workers(self, n=1): to allow a user to override the internal settings would be very useful. Very happy to code and document here, mostly trying to figure out the current bounds of the project.
I think there is something to do with the cores/processes/threads/ncpus/ressources_spec.. At least some standardisation between JobQueueCluster implementations. I'm not sure how it should look like though, we previously removed the use of threads in order to replace it by cores. But maybe we should remove ncpus and alike and add backs threads...
It would be more than welcome if you could propose some simple design choices here so we can discuss it, and then if we agree on something, propose a PR!
For the second part on the larger context, I'm not sure I get your point, but maybe it has another scope and should be discussed in another issue?
I am not entirely sure what the mental model you want to convey so this project remains relatively easy for new users while being mutable for complex scenarios. But the above while cover our primary use case.
It feels like what you want is an advanced use case, so I don't think resource_spec should be automatically inferred from cores and processes. I would recommend:
setting cores and processes in terms of how many cores/processes/threads you want each dask-worker to have
specifying explicitly your scheduler-specific resource_spec to say that each job would get the number of threads you want your C++ code to use
Replying to the above : I think resource_spec is by worker, not by task and it is specific to some queue systems.
IMO we have three levels:
the real number of cores that will be allocated, which should always be specified by design
the number of processes, ie the number of GIL bound tasks that can be executed, and the number of threads per process, ie how many tasks each process can execute
the number of threads by task
The problem is that the number of cores is supposed to be the number of tasks in our current model, ie threads_by_task=1.
I propose two alternatives:
a new parameter threads_by_task that divides threads
a boolean one_task_per_process defaulting to False
I suppose that when handling parallelism manually, one doesn't want to share a process with another task.
one_task_per_process=True sets threads=1 in the dask worker options and still allocates cores/processes threads per process. Since we now have only one task per process, the handcrafted parallelism can allocate up to threads without lying to the scheduler.
I would be more in favor of a boolean than threads_by_task that adds complexity to the system and might break existing parallelism mechanisms if the handcrafted code is executed by a thread (not sure about that).
@louisabraham it is not completely straightforward to follow what you are saying, and from what I understand it feels like dask.distributed is the right level to address some of your points (for example, I guess by task you mean a function that is used in client.submit right?)
Granted there are plenty of things that could be added/improved in dask-jobqueue and suggestions are always more than welcome! I would suggest we start from precise use cases like the one in the original post and see how we can tackle them.
For anything non-trivial, my opinion that you will have to specify resource_spec, and so you will have to understand a bit the underlying scheduler specificities. Given the variability of the different schedulers (and even sometimes the variability of the installs for a given scheduler), I would be a bit hesitant about providing a layer that allows to forget about scheduler-specific things.
My personal opinion is that being able to easily create heterogeneous clusters would be the right direction in which to extend (but even then maybe some of this work may happen in dask.distributed).
is that there is no variable that can track the total number of CPUs allocated and that the code is scheduler specific.
On the other hand, cores totals to the total number of tasks that can be executed concurrently.
If you don't want to break this, threads_by_task would allocate threads_by_task*cores CPUs.
We have this use case of heterogeneous clusters at our site. We have modular supercomputing, with pure CPU nodes, nodes with GPUs and KNL nodes all available.
While this is heterogeneous architectures, we also have the use case of heterogeneous resources within clusters. We want the ability to self-manage some of the resources (see #84 (comment) for the use case). At present we simply use job_extra to override the resource request that dask-jobqueue makes
job_extra=[
'-N %s' % nodes,
'--tasks-per-node=%s' % tasks_per_node,
'--cpus-per-task=%s' % cpus_per_task,
# Override the default -n 1 value with the calculated value
'-n %s' % total_tasks
],
It seem ultimately that you do not want users touching resource_spec or similar where possible as it invalidates all of your internal tracking in addition to being custom per scheduler.
I think the question we want to ask now is: should cores be the number of CPUs or the number of tasks that can be executed at the same time?
I would be hesitant to override the "core" definition with supercomputers as it is well defined there, where "tasks" is well defined in Dask.
Heterogeneous clusters would difficult to tackle in a generic way I think. It might be worth adding a start_worker() that allows full specification of the dask-worker CLI as intermediate step.
I think heterogeneous clusters are out of the topic.
Yep I agree, we should address this in another issue if this is something that interests people. See #103 already open.
For the other part of the rich discussion here, it's a complicated desgin choice, but I thin I'm more in favor of avoiding jobqueue system specific kwargs as much as possible. I think I would better like what @dgasmith proposes: having three kwargs:
cores: which is the ncpus reserved in jobqueue system, and the default total cores used by dask-worker command. e.g. worker_threads = cores / processes.
processes: default to one, only useful for dask-worker command.
threads_per_process or something like that: default to none, only useful for dask-worker command.
For job scheduler specificities, we would rely only on job_extra, as @ocaisa is doing. This would mean removing resources_spec from PBSCluster or ncpus from SlurmCluster.
I've two remaining concerns:
How should we handle the memory part, which may not be expressed identically between dask and jobqueue systems, can we have only one parameter easilly?
Would we be able to override resources_spec for example in job_extra if really needed, e.g. if there are for example two #PBS -l select=1:ncpus=24 in the job script, would the second be prioritize over the first? Or should we put job_extra first depending on the scheduler?
In your proposal, isn't cores = processes * threads_per_process?
Not always, no. In what I propose, your threads_by_task would be cores / (processes * threads_per_process). Or to put it differently and perhaps more clearer: cores = processes * threads_per_processes * threads_per_tasks.
In my opinion, threads_per_tasks is application specific, and should not appear in dask-jobqueue. dask-jobqueue books scheduler resources, and then start dask distributed with a given set of parameters. Possibly less dask threads than reserved cores, but in some cases we've also seen more threads than reserved cores.
I'm getting headaches as well about this 😉 : I have a similar problem. Each one of my tasks (embarrassingly parallel) manages threading internally with OpenMP and needs 8 cores. I did start 2 workers using
but when i then map my (OpenMP parallalized) function using client.map with 16 parametersets - it runs many tasks at the same time on each worker. I want to have a maximum of one task for each worker (that means two instances of each function running at the same time).
fromdask.distributedimportClientfromdask_jobqueueimportSLURMCluster# throughcluster=SLURMCluster(cores=8, processes=1, memory='7GB',
# each dask worker declares it has an amount 1# of the resource named "processes"extra=['--resources processes=1'])
client=Client(cluster)
n_workers=10cluster.scale(n_workers)
# resources ensure that at most one task (i.e. function in `.submit`)# will run on each dask workerfutures= [client.submit(function_calling_multithreaded_cpp_code, arg,
# each task declares that they need an amount 1# of the resource named "processes" resources={'processes': 1})
forarginarg_list]
@lesteve doesn't work when leaving the resources out of the map command - trying with resources in map. I found a fix and am gonna post it after this next test.
@lesteveresources is not a document keyword for either submit or map but it does work. Thanks! it would be nice to somehow be able to tell the cluster that one worker has 8 cpus and can only schedule one task
IMO dask resources is the "dask way" of doing what you want. In particular, note resources is not at the cluster level but at the task (i.e. function in .submit) level, which makes a lot of sense because some of the tasks may use multiple threads but some of the other tasks may not.
I completely agree that resources are not very easy to discover when you are new to dask. I'd be in favour of adding an example that explains how to execute a function using multi-threading in docs/source/examples.rst. PR more than welcome!
@lesteve I guess it makes sense if you want to be that fine-grained that different tasks can have different resource requests. I still don't understand what the resources is for the cluster and for submit. It seems one worker can do more than one task at the same time (I've seen the word slot mentioned) - what do I tell the workers in the cluster creation (they have one slot? )
I still don't understand what the resources is for the cluster and for submit.
Right sorry, I am going to try to explain better (I'll edit my snippet above too to make it clearer):
# each dask worker declare it has processes=1cluster=SLURMCluster(cores=8, processes=1, memory='7GB', extra=['--resources processes=1'])
# each task (e.g. function submission) declare they need processes=1# because each dask worker declared it had processes=1 this will ensure that # at most one task runs on each dask workerfutures= [client.submit(function_calling_multithreaded_cpp_code, arg,
resources={'processes': 1})
thank you!! that helped. So now I do adaptive scaling and it seems to only run on one worker. I 've had that before - where it doesn't seem to load-balance. Is this something that should happen or do I need to set this up?
I'm first trying to see if that is a problem with manual scaling as well. Ah ... the resources - it seems to be arbitrary what I name the resources. As my code is called TARDIS - I could say that each worker has one heart_of_tardis which is needed for each compilation - there is nothing special about the keyword processes, right?
Activity
guillaumeeb commentedon Oct 23, 2018
Funnily enough, I think we just had a conversation on this point in #179.
As you point out
cores/processeskwargs are used both to configure dask-worker command, and to reserve jobqueue system resources. However, the second part is just by default guessed from this kwargs. In every JobQueueCluster implementation, there should be anotherkwargallowing you to force different resource reservation on the underlying scheduling system. For example with PBSCluster:or LSFCluster:
It seems we should better document this though, and this seems useful, we were previously thinking of removing this possibility...
dgasmith commentedon Oct 23, 2018
saw on LSF you could select cpus, but I wasn't aware of the PBSCluster abilities to write out resource specs. To make things simpler, would it be possible to set the number of threads manually so that you would have
nthreads = Nonewhich would default to current behavior.It is worth considering this in a larger context where one might wish to start heterogeneous workers with labels where expanding
def start_workers(self, n=1):to allow a user to override the internal settings would be very useful. Very happy to code and document here, mostly trying to figure out the current bounds of the project.guillaumeeb commentedon Oct 23, 2018
I think there is something to do with the cores/processes/threads/ncpus/ressources_spec.. At least some standardisation between JobQueueCluster implementations. I'm not sure how it should look like though, we previously removed the use of
threadsin order to replace it bycores. But maybe we should removencpusand alike and add backsthreads...It would be more than welcome if you could propose some simple design choices here so we can discuss it, and then if we agree on something, propose a PR!
For the second part on the larger context, I'm not sure I get your point, but maybe it has another scope and should be discussed in another issue?
dgasmith commentedon Oct 23, 2018
I think my proposal would be similar to the discussed. Scanning through
core.pyI see the following points:I am not entirely sure what the mental model you want to convey so this project remains relatively easy for new users while being mutable for complex scenarios. But the above while cover our primary use case.
I will hold off the second part for later.
guillaumeeb commentedon Oct 24, 2018
Ping @mrocklin @jhamman @willirath @lesteve for opinion on how to best handle this.
No it's thread, or maybe cores divided per process. We've got one running worker per worker process actually.
lesteve commentedon Oct 24, 2018
It feels like what you want is an advanced use case, so I don't think
resource_specshould be automatically inferred fromcoresandprocesses. I would recommend:coresandprocessesin terms of how many cores/processes/threads you want each dask-worker to haveresource_specto say that each job would get the number of threads you want your C++ code to uselouisabraham commentedon Oct 24, 2018
Replying to the above : I think resource_spec is by worker, not by task and it is specific to some queue systems.
IMO we have three levels:
The problem is that the number of cores is supposed to be the number of tasks in our current model, ie threads_by_task=1.
I propose two alternatives:
I suppose that when handling parallelism manually, one doesn't want to share a process with another task.
one_task_per_process=True sets threads=1 in the dask worker options and still allocates cores/processes threads per process. Since we now have only one task per process, the handcrafted parallelism can allocate up to threads without lying to the scheduler.
I would be more in favor of a boolean than threads_by_task that adds complexity to the system and might break existing parallelism mechanisms if the handcrafted code is executed by a thread (not sure about that).
lesteve commentedon Oct 24, 2018
@louisabraham it is not completely straightforward to follow what you are saying, and from what I understand it feels like dask.distributed is the right level to address some of your points (for example, I guess by task you mean a function that is used in
client.submitright?)Granted there are plenty of things that could be added/improved in dask-jobqueue and suggestions are always more than welcome! I would suggest we start from precise use cases like the one in the original post and see how we can tackle them.
For anything non-trivial, my opinion that you will have to specify
resource_spec, and so you will have to understand a bit the underlying scheduler specificities. Given the variability of the different schedulers (and even sometimes the variability of the installs for a given scheduler), I would be a bit hesitant about providing a layer that allows to forget about scheduler-specific things.My personal opinion is that being able to easily create heterogeneous clusters would be the right direction in which to extend (but even then maybe some of this work may happen in dask.distributed).
louisabraham commentedon Oct 24, 2018
I didn't intend it this way.
Yes.
Totally agree. To achieve what the author wants with my proposal, the parameters are
What disturbs me in @guillaumeeb's immediate fix (it is the only way to do it currently,
which is the real problem)
is that there is no variable that can track the total number of CPUs allocated and that the code is scheduler specific.
On the other hand, cores totals to the total number of tasks that can be executed concurrently.
If you don't want to break this,
threads_by_taskwould allocatethreads_by_task*coresCPUs.For the OP's problem:
I think the question we want to ask now is: should
coresbe the number of CPUs or the number of tasks that can be executed at the same time?ocaisa commentedon Oct 24, 2018
We have this use case of heterogeneous clusters at our site. We have modular supercomputing, with pure CPU nodes, nodes with GPUs and KNL nodes all available.
While this is heterogeneous architectures, we also have the use case of heterogeneous resources within clusters. We want the ability to self-manage some of the resources (see #84 (comment) for the use case). At present we simply use
job_extrato override the resource request thatdask-jobqueuemakesThis results in a submission script like
I don't know if the same approach would work with other schedulers.
dgasmith commentedon Oct 24, 2018
It seem ultimately that you do not want users touching
resource_specor similar where possible as it invalidates all of your internal tracking in addition to being custom per scheduler.I would be hesitant to override the "core" definition with supercomputers as it is well defined there, where "tasks" is well defined in Dask.
Heterogeneous clusters would difficult to tackle in a generic way I think. It might be worth adding a
start_worker()that allows full specification of thedask-workerCLI as intermediate step.PS: Hey @ocaisa!
louisabraham commentedon Oct 24, 2018
Ok, then my proposal is the following:
A
threads_by_taskdefaulting to 1.Each dask worker receives the parameters
processesandthreadslike now.Jobqueue allocates
cores * threads_by_taskCPUs wherecores = processes * threads.I think heterogeneous clusters are out of the topic.
guillaumeeb commentedon Oct 27, 2018
Yep I agree, we should address this in another issue if this is something that interests people. See #103 already open.
For the other part of the rich discussion here, it's a complicated desgin choice, but I thin I'm more in favor of avoiding jobqueue system specific kwargs as much as possible. I think I would better like what @dgasmith proposes: having three kwargs:
cores: which is the ncpus reserved in jobqueue system, and the default total cores used by dask-worker command. e.g. worker_threads = cores / processes.processes: default to one, only useful for dask-worker command.threads_per_processor something like that: default to none, only useful for dask-worker command.For job scheduler specificities, we would rely only on
job_extra, as @ocaisa is doing. This would mean removingresources_specfrom PBSCluster orncpusfrom SlurmCluster.I've two remaining concerns:
Any thought?
louisabraham commentedon Oct 27, 2018
@guillaumeeb I'm not sure to follow.
In your proposal, isn't
cores = processes * threads_per_process?Maybe your
threads_per_processis the same as mythreads_by_task, aka the number of threads that execute one task.guillaumeeb commentedon Oct 27, 2018
Not always, no. In what I propose, your
threads_by_taskwould becores / (processes * threads_per_process). Or to put it differently and perhaps more clearer:cores = processes * threads_per_processes * threads_per_tasks.In my opinion, threads_per_tasks is application specific, and should not appear in dask-jobqueue. dask-jobqueue books scheduler resources, and then start dask distributed with a given set of parameters. Possibly less dask threads than reserved cores, but in some cases we've also seen more threads than reserved cores.
38 remaining items
wkerzendorf commentedon Jan 31, 2019
I'm getting headaches as well about this 😉 : I have a similar problem. Each one of my tasks (embarrassingly parallel) manages threading internally with OpenMP and needs 8 cores. I did start 2 workers using
but when i then map my (OpenMP parallalized) function using
client.mapwith 16 parametersets - it runs many tasks at the same time on each worker. I want to have a maximum of one task for each worker (that means two instances of each function running at the same time).wkerzendorf commentedon Jan 31, 2019
I'm trying to ask a similar question here as well https://stackoverflow.com/questions/54469195/dask-joblib-ipyparallel-and-other-schedulers-for-embarrassingly-parallel-probl
lesteve commentedon Feb 1, 2019
Can you try this and report back?
wkerzendorf commentedon Feb 1, 2019
@lesteve won't the problem be that the futures go out of scope. Do I have to do fire_and_forget?
lesteve commentedon Feb 1, 2019
Sorry I edited my snippet above. You may be able to use
.mapwith resources but I have not checked ...wkerzendorf commentedon Feb 1, 2019
@lesteve doesn't work when leaving the
resourcesout of the map command - trying withresourcesin map. I found a fix and am gonna post it after this next test.wkerzendorf commentedon Feb 1, 2019
@lesteve
resourcesis not a document keyword for eithersubmitormapbut it does work. Thanks! it would be nice to somehow be able to tell the cluster that one worker has 8 cpus and can only schedule one tasklesteve commentedon Feb 1, 2019
IMO dask resources is the "dask way" of doing what you want. In particular, note resources is not at the cluster level but at the task (i.e. function in
.submit) level, which makes a lot of sense because some of the tasks may use multiple threads but some of the other tasks may not.I completely agree that resources are not very easy to discover when you are new to dask. I'd be in favour of adding an example that explains how to execute a function using multi-threading in
docs/source/examples.rst. PR more than welcome!wkerzendorf commentedon Feb 1, 2019
@lesteve I guess it makes sense if you want to be that fine-grained that different tasks can have different resource requests. I still don't understand what the
resourcesis for the cluster and for submit. It seems one worker can do more than one task at the same time (I've seen the wordslotmentioned) - what do I tell the workers in the cluster creation (they have oneslot? )thanks for your help btw!
lesteve commentedon Feb 1, 2019
Right sorry, I am going to try to explain better (I'll edit my snippet above too to make it clearer):
You can look at http://distributed.dask.org/en/latest/resources.html for a more detailed explanation of dask resources.
wkerzendorf commentedon Feb 1, 2019
thank you!! that helped. So now I do adaptive scaling and it seems to only run on one worker. I 've had that before - where it doesn't seem to load-balance. Is this something that should happen or do I need to set this up?
lesteve commentedon Feb 1, 2019
I don't think it is expected, can you open a new issue about this?
wkerzendorf commentedon Feb 1, 2019
I'm first trying to see if that is a problem with manual scaling as well. Ah ... the
resources- it seems to be arbitrary what I name the resources. As my code is called TARDIS - I could say that each worker has oneheart_of_tardiswhich is needed for each compilation - there is nothing special about the keywordprocesses, right?guillaumeeb commentedon Feb 4, 2019
Okay, I'm going to close this discussion. It is two long already. I've created #231 as an outcome we all agree with.
I'm still open if someone want to propose a PR to add
nthreadslike kwarg, and see how it looks.