Repository navigation
Description
I am trying to use Dask to do parallel processing on multiple nodes on supercomputing resources - yet the Dask-distributed map only takes advantage of one of the nodes. Note that I put this up on stackoverflow but didn't get attention so now I'm giving here a go.
Here is a test script I am using to set up the client and perform a simple operation:
import time
from distributed import Client
from dask_jobqueue import SLURMCluster
from socket import gethostname
def slow_increment(x):
time.sleep(10)
return [x + 1, gethostname(), time.time()]
cluster = SLURMCluster(
queue='somequeue',
cores=2,
memory='128GB',
project='someproject',
walltime='00:05:00',
job_extra=['-o myjob.%j.%N.out',
'-e myjob.%j.%N.error'],
env_extra=['export I_MPI_FABRICS=dapl',
'source activate dask-jobqueue'])
cluster.scale(2)
client = Client(cluster)
A = client.map(slow_increment, range(8))
B = client.gather(A)
print(client)
for res in B:
print(res)
client.close()And here is the output:
<Client: scheduler='tcp://someip' processes=2 cores=4>
[1, 'bdw-0478', 1540477582.6744401]
[2, 'bdw-0478', 1540477582.67487]
[3, 'bdw-0478', 1540477592.68666]
[4, 'bdw-0478', 1540477592.6879778]
[5, 'bdw-0478', 1540477602.6986163]
[6, 'bdw-0478', 1540477602.6997452]
[7, 'bdw-0478', 1540477612.7100565]
[8, 'bdw-0478', 1540477612.711296]
While printing out the client info indicates that Dask has the correct number of nodes (processes) and tasks per node (cores), the socket.gethostname() output and time-stamps indicate that the second node isn't used. I do know that dask-jobqueue successfully requested two nodes, and that both jobs complete at the same time. I tried using different MPI Fabrics for inter- and intra-node communication (e.g. tcp, shm:tcp, shm:ofa, ofa, ofi, dapl) but this did not change the result. I also tried removing the "export I_MPI_FABRICS" command and using the "interface" option, but this caused the code to hang.
Thanks in advance for any assistance.
-Noah
Activity
guillaumeeb commentedon Dec 4, 2018
Sorry we miss this question, I do not personnaly watch Stack Overflow, but I should. You issue may also belong to dask-jobqueue, but that's not really important for the time being.
After a quick glance at your code, I cannot see anything wrong. So we will need to find a way to debug what's going on.
Dask does not use MPI for communication, only plain TCP, so either ethernet interfaces, or IP over IB. Did you try without any fabrics, and without interface option ?
Some other thoughts:
jhamman commentedon Dec 4, 2018
I suggest we move this issue to dask-jobqueue. One of the dask devs may be able to actually move this issue there (new GH feature) or @npaulson can just cross post.
mrocklin commentedon Dec 4, 2018
Transferred. Also gave all org members with the ability to delete issues, which I hope implies the ability to move them.
npaulson commentedon Dec 4, 2018
Thank you for taking an interest in my issue!
@guillaumeeb, below I'm including short descriptions of my investigations into your various debugging suggestions and after the full code, it's output and stderror.
When I don't explicitly define the fabrics and don't include an interface option the code runs similarly as before.
To check this I printed the client before the gather operation and it appears to have formed properly.
I haven't yet figured out how do to this, though I'm looking into it next.
The stdout is empty but there are details in stderr.
I have enabled debugging mode and included the output below. Some of the other suggestions seem to deal with getting the jobs themselves through SLURM, though I don't seem to be having a problem in that regard.
Here is the updated version of my code:
Here is the output of my code with logging enabled:
Here is the stderror for node 00048:
Here is the stderror for node 00285:
guillaumeeb commentedon Dec 6, 2018
I don't think this would change the behavior you see, but you should set
local-directorykwarg to /tmp, /scratch or any other space local to you compute nodes.Still no idea here, you should try to use the dashboard to se if you see some strange things.
npaulson commentedon Dec 11, 2018
I've tried accessing the dashboard, which sometimes populates with the workers but other times does not. When it does populate with the workers, it only shows two - which I assume are the workers associated with the single node that reports back.
guillaumeeb commentedon Dec 11, 2018
If it shoes two workers, then it's showing both nodes you're using. You've got one worker process per node with your config. It is really strange that tasks are only executed on one node. You should be able to see worker activity with the dashboard, and see where your tasks are executed.
goraj commentedon Dec 12, 2018
I believe I have the same issue using SGE/UGE, I can start multiple job scripts but every job runs on the same node/PID
Result:
qstat output:
mrocklin commentedon Dec 12, 2018
My guess is that once the first worker arrives it gets all of the work, and that this work finishes well before the second worker arrives a subsecond later. Maybe try waiting until all of the workers have arrived?
goraj commentedon Dec 12, 2018
@mrocklin Yes that would make sense. However the workers all spawn and run nearly instantly and at the same time.
Still when submitting long running jobs they still all get submitted to the same node and run on the same PID.
Sleeping between scale and submit seems to solves this. I assume my idea of the scheduler is wrong. The workers all spawn and run well before the first job is processed. And still all of them are pushed to that node without the sleep between scale and submit.
For future reference: The following script is able to run all jobs on different nodes, unfortunately it requires all workers to run before we can submit:
npaulson commentedon Dec 12, 2018
I modified my code to include @mrocklin 's suggestion but still only one of the nodes is doing any work. I verified this on the dashboard by having my task instantiate a large numpy array. On the dashboard I see both nodes being initialized, but processing is only done on one of the nodes.
@guillaumeeb , I also simplified the script so that only one process is started per node.
The updated script is included below:
mrocklin commentedon Dec 12, 2018
guillaumeeb commentedon Dec 12, 2018
There are two different situations here.
@goraj why do you want your tasks to be submitted to different workers? I think @mrocklin comments are for you. There are other solutions if you want only one task per node than using sleep and waiting for all the cluster to be up.
@npaulson I still don't see where the problem can be. I will try to execute your code, but I don't expect to run on the same issue. There should be scheduling error if no tasks can be sent to one of your worker. @mrocklin is there a way to see this kind of errors?
goraj commentedon Dec 13, 2018
@guillaumeeb so I have hundreds of very long running jobs that are not thread-safe.
I also want each to run on its own cluster node and use all available cpus there.
Unfortunately I cannot figure out how to get each job to one cluster node using dask-jobqueue without using the wait like so:
It is likely that my mental model is wrong and I would highly appreciate any tips or changes I should consider. Thank you all for the help and sorry for hijacking this issue, I thought I had the same problem as @npaulson.
30 remaining items
mrocklin commentedon Jun 22, 2020
lesteve commentedon Jun 22, 2020
You may be interested to look at: https://examples.dask.org/machine-learning/torch-prediction.html. It is with a LocalCluster but easy to translate to a SLURMCluster.
I would say in a typical HPC cluster this is rather unusual but I may be biased by the HPC clusters I am familiar with ... generally you have no idea how long you have to wait for your one job to start (it can depend on how people are using the cluster, on your past usage and probably on other factors) and even less for many jobs to start.
Work stealing does that in principle automatically for you. If all your jobs do start running (i.e.
squeueshows them running) as you say, this does point towards work stealing not kicking in your use case, hard to tell why but maybe the doc can help.ocaisa commentedon Jun 22, 2020
I also think dask-mpi is what you want for your use case, the workers will start instantly and you can tweak your SLURM job requirements to give you the distribution you want (1 MPI task per node would mean one worker per node, no need for a
mapstep)fabiansvara commentedon Jun 22, 2020
If that worked it would make the whole issue moot. According to the work stealing docs:
... depending on how exactly I interpret this sentence, it might explain what's going on. I instantiate the
SLURMClusterwithextra=['--resources GPU=1']and callmapwithresources={'GPU': 1}. This is because the GPU nodes also have a lot of CPUs, so they could also be used for running multiple CPU-bound jobs in other cases.If I interpret the sentence from the doc to mean "jobs where resources were specified will not be stolen", then that's the problem. Here in my case, it would be perfectly fine for other workers that have the same resource available to steal the jobs.
Edit: It also explains the trouble that the person in #304 was having.
lesteve commentedon Jun 22, 2020
This was indeed a limitation but a PR supposed to fix this (dask/distributed#3069) has been merged. It seems like this is in 2.12 so maybe check that you distributed version is recent enough.
If that still does not work for you this could be a problem with the PR or work stealing that does not kick in for some reason in your particular case ... hard to tell ...
And of course the distributed doc may also need to be fixed as well ...
fabiansvara commentedon Jun 22, 2020
Hm, I have
2.18.0. Anything I can do to narrow down what's going on?lesteve commentedon Jun 22, 2020
Yeah that was my guess that your version was recent enough.
could you first post a snippet to show how you are creating your cluster and using it. In an ideal world a stand-alone snippet reproducing the problem would be great.
Here are a list of suggestions at this point:
fabiansvara commentedon Jun 23, 2020
Finally found some time to experiment with this.
Here's my complete testing code:
This prints the following:
(the individual lines are separated by
... I removed that from the output above for clarity. This seems to be caused be the creation / closing of the cluster in the loop; it doesn't influence the results, which are identical when this is not run in a loop.)
Anyway, as you can see, the issue only occurs in the
wait=False, with_resource=True, cores=20case, where the jobs run sequentially. The workers are all there, but only one of them is doing anything. This is what it looks like in the dashboard:lesteve commentedon Jun 24, 2020
Thanks a lot for doing this! So it looks like work-stealing with resources does happen when cores=1, which is good to confirm.
The case where it does not work is when you have cores=20. I am not an expert on the work stealing logic, but I can only guess that work-stealing does not kick in because the scheduler sees 20 slots on the first node (one slot for each core) with 5 tasks to execute so the worker doesn't seem busy and work stealing does not seem worth it. It could be interesting to confirm this hypothesis by submitting many more short tasks and see whether work stealing happens. It could also be worth getting some inputs by @mrocklin to make sure my hypothesis seems reasonable to him ...
Maybe this is something that can be improved in distributed, not sure. I guess it should be possible to create a reproducer with
distributed.SSHClusterso that more people are likely to look at it.fabiansvara commentedon Jun 25, 2020
I looked into the documentation but couldn't find out how to create an
SSHClusterwith resources, not sure I can be of any help there. Should I create an issue specifically about work stealing on the distributed tracker?appassionate commentedon Nov 25, 2022
@fabiansvara @lesteve
Hi, sorry for discussing this in this old issue, any news in this using of job-queue?
In my case, i want to map more "MPI" jobs in client by cluster.scale.
Dask scheduler seems to manage task by the total threads in the workers. If cores to be 32(my hpc cores per node) ,there will be 32 threads in a worker, and any client.submit method will be executed as one thread ( i guess). So It is tricky to set cores to be 1, let the scheduler know there only one thread in a work, but actually, task in this worker will launch a MPI job, which might be "work-stealing " you are talking about? thanks.
Here is my cluster config.
Is there way that dask scheduler not manage submit task by threads but the worker_num?
Any suggestions will be helpful! thank u! :)
ocaisa commentedon Nov 25, 2022
@appassionate We created a library that does what you are asking for but I admit it requires quite a bit of configuration since you need to tell it about the system and how you launch MPI jobs there. The library is at https://github.com/E-CAM/jobqueue_features and there's a tutorial at https://github.com/E-CAM/jobqueue_features_workshop_materials (and you can find a recording of the tutorial at https://www.youtube.com/watch?v=FpMua8iJeTk&ab_channel=E-CAM).
I haven't touched it in a few months, need to check if our CI is still passing.That package is working with the latest version of jobqueue (0.8.1)appassionate commentedon Nov 27, 2022
@ocaisa waow cool! Many thanks!!
guillaumeeb commentedon Nov 29, 2022
@appassionate, with your comment, it is not really clear to me what you're trying to achieve.
Anyway, if @ocaisa answer suits you, this is perfect, if not, I encourage you to open a new issue and try to make your issue a bit clearer.
appassionate commentedon Dec 1, 2022
Thanks for your suggestion! jobqueue_features have customized the "SlurmCluster" for some MPI using, i believe there will be some using in such as "more nodes" in slurm which is suitable for me.