Debian Codegraph @

docs/source/deploying-hpc.rst

raw
1 High Performance Computers
2 ==========================
3
4 Relevant Machines
5 -----------------
6
7 This page includes instructions and guidelines when deploying Dask on high
8 performance supercomputers commonly found in scientific and industry research
9 labs. These systems commonly have the following attributes:
10
11 1. Some mechanism to launch MPI applications or use job schedulers like
12 SLURM, SGE, TORQUE, LSF, DRMAA, PBS, or others
13 2. A shared network file system visible to all machines in the cluster
14 3. A high performance network interconnect, such as Infiniband
15 4. Little or no node-local storage
16
17
18 Where to start
19 --------------
20
21 Most of this page documents various ways and best practices to use Dask on an
22 HPC cluster. This is technical and aimed both at users with some experience
23 deploying Dask and also system administrators.
24
25 The preferred and simplest way to run Dask on HPC systems today both for new,
26 experienced users or administrator is to use
27 `dask-jobqueue <https://jobqueue.dask.org>`_.
28
29 However, dask-jobqueue is slightly oriented toward interactive analysis usage,
30 and it might be better to use tools like dask-mpi in some routine batch
31 production workloads.
32
33
34 Dask-jobqueue and Dask-drmaa
35 ----------------------------
36
37 `dask-jobqueue <https://jobqueue.dask.org>`_ provides cluster managers for PBS,
38 SLURM, LSF, SGE and other resource managers. You can launch a Dask cluster on
39 these systems like this.
40
41 .. code-block:: python
42
43 from dask_jobqueue import PBSCluster
44
45 cluster = PBSCluster(cores=36,
46 memory="100GB",
47 project='P48500028',
48 queue='premium',
49 interface='ib0',
50 walltime='02:00:00')
51
52 cluster.scale(100) # Start 100 workers in 100 jobs that match the description above
53
54 from dask.distributed import Client
55 client = Client(cluster) # Connect to that cluster
56
57 Dask-jobqueue provides a lot of possibilities like adaptive dynamic scaling
58 of workers, we recommend reading the `dask-jobqueue documentation
59 <https://jobqueue.dask.org>`_ first to get a basic system running and then
60 returning to this documentation for fine-tuning if necessary.
61
62
63 Using MPI
64 ---------
65
66 You can launch a Dask cluster using ``mpirun`` or ``mpiexec`` and the
67 `dask-mpi <http://mpi.dask.org/en/latest/>`_ command line tool.
68
69 .. code-block:: bash
70
71 mpirun --np 4 dask-mpi --scheduler-file /home/$USER/scheduler.json
72
73 .. code-block:: python
74
75 from dask.distributed import Client
76 client = Client(scheduler_file='/path/to/scheduler.json')
77
78 This depends on the `mpi4py <https://mpi4py.readthedocs.io/>`_ library. It only
79 uses MPI to start the Dask cluster and not for inter-node communication. MPI
80 implementations differ: the use of ``mpirun --np 4`` is specific to the
81 ``mpich`` or ``open-mpi`` MPI implementation installed through conda and linked
82 to mpi4py.
83
84 .. code-block:: bash
85
86 conda install mpi4py
87
88 It is not necessary to use exactly this implementation, but you may want to
89 verify that your ``mpi4py`` Python library is linked against the proper
90 ``mpirun/mpiexec`` executable and that the flags used (like ``--np 4``) are
91 correct for your system. The system administrator of your cluster should be
92 very familiar with these concerns and able to help.
93
94 In some setups, MPI processes are not allowed to fork other processes. In this
95 case, we recommend using ``--no-nanny`` option in order to prevent dask from
96 using an additional nanny process to manage workers.
97
98 Run ``dask-mpi --help`` to see more options for the ``dask-mpi`` command.
99
100
101 Using a Shared Network File System and a Job Scheduler
102 ------------------------------------------------------
103
104 .. note:: This section is not necessary if you use a tool like dask-jobqueue.
105
106 Some clusters benefit from a shared File System (NFS, GPFS, Lustre or alike),
107 and can use this to communicate the scheduler location to the workers::
108
109 dask-scheduler --scheduler-file /path/to/scheduler.json # writes address to file
110
111 dask-worker --scheduler-file /path/to/scheduler.json # reads file for address
112 dask-worker --scheduler-file /path/to/scheduler.json # reads file for address
113
114 .. code-block:: python
115
116 >>> client = Client(scheduler_file='/path/to/scheduler.json')
117
118 This can be particularly useful when deploying ``dask-scheduler`` and
119 ``dask-worker`` processes using a job scheduler like
120 SGE/SLURM/Torque/etc. Here is an example using SGE's ``qsub`` command::
121
122 # Start a dask-scheduler somewhere and write the connection information to a file
123 qsub -b y /path/to/dask-scheduler --scheduler-file /home/$USER/scheduler.json
124
125 # Start 100 dask-worker processes in an array job pointing to the same file
126 qsub -b y -t 1-100 /path/to/dask-worker --scheduler-file /home/$USER/scheduler.json
127
128 Note, the ``--scheduler-file`` option is *only* valuable if your scheduler and
129 workers share a network file system.
130
131
132 High Performance Network
133 ------------------------
134
135 Many HPC systems have both standard Ethernet networks as well as
136 high-performance networks capable of increased bandwidth. You can instruct
137 Dask to use the high-performance network interface by using the ``--interface``
138 keyword with the ``dask-worker``, ``dask-scheduler``, or ``dask-mpi`` commands or
139 the ``interface=`` keyword with the dask-jobqueue ``Cluster`` objects:
140
141 .. code-block:: bash
142
143 mpirun --np 4 dask-mpi --scheduler-file /home/$USER/scheduler.json --interface ib0
144
145 In the code example above, we have assumed that your cluster has an Infiniband
146 network interface called ``ib0``. You can check this by asking your system
147 administrator or by inspecting the output of ``ifconfig``
148
149 .. code-block:: bash
150
151 $ ifconfig
152 lo Link encap:Local Loopback # Localhost
153 inet addr:127.0.0.1 Mask:255.0.0.0
154 inet6 addr: ::1/128 Scope:Host
155 eth0 Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX # Ethernet
156 inet addr:192.168.0.101
157 ...
158 ib0 Link encap:Infiniband # Fast InfiniBand
159 inet addr:172.42.0.101
160
161 https://stackoverflow.com/questions/43881157/how-do-i-use-an-infiniband-network-with-dask
162
163
164 Local Storage
165 -------------
166
167 Users often exceed memory limits available to a specific Dask deployment. In
168 normal operation, Dask spills excess data to disk, often to the default
169 temporary directory.
170
171 However, in HPC systems this default temporary directory may point to an
172 network file system (NFS) mount which can cause problems as Dask tries to read
173 and write many small files. *Beware, reading and writing many tiny files from
174 many distributed processes is a good way to shut down a national
175 supercomputer*.
176
177 If available, it's good practice to point Dask workers to local storage, or
178 hard drives that are physically on each node. Your IT administrators will be
179 able to point you to these locations. You can do this with the
180 ``--local-directory`` or ``local_directory=`` keyword in the ``dask-worker``
181 command::
182
183 dask-mpi ... --local-directory /path/to/local/storage
184
185 or any of the other Dask Setup utilities, or by specifying the
186 following :doc:`configuration value <../../configuration>`:
187
188 .. code-block:: yaml
189
190 temporary-directory: /path/to/local/storage
191
192 However, not all HPC systems have local storage. If this is the case then you
193 may want to turn off Dask's ability to spill to disk altogether.
194 See :doc:`this page <worker-memory>` for more information on Dask's memory policies.
195 Consider changing the following values in your ``~/.config/dask/distributed.yaml`` file
196 to disable spilling data to disk:
197
198 .. code-block:: yaml
199
200 distributed:
201 worker:
202 memory:
203 target: false # don't spill to disk
204 spill: false # don't spill to disk
205 pause: 0.80 # pause execution at 80% memory use
206 terminate: 0.95 # restart the worker at 95% use
207
208 This stops Dask workers from spilling to disk, and instead relies entirely on
209 mechanisms to stop them from processing when they reach memory limits.
210
211 As a reminder, you can set the memory limit for a worker using the
212 ``--memory-limit`` keyword::
213
214 dask-mpi ... --memory-limit 10GB
215
216
217 Launch Many Small Jobs
218 ----------------------
219
220 .. note:: This section is not necessary if you use a tool like dask-jobqueue.
221
222 HPC job schedulers are optimized for large monolithic jobs with many nodes that
223 all need to run as a group at the same time. Dask jobs can be quite a bit more
224 flexible: workers can come and go without strongly affecting the job. If we
225 split our job into many smaller jobs, we can often get through the job
226 scheduling queue much more quickly than a typical job. This is particularly
227 valuable when we want to get started right away and interact with a Jupyter
228 notebook session rather than waiting for hours for a suitable allocation block
229 to become free.
230
231 So, to get a large cluster quickly, we recommend allocating a dask-scheduler
232 process on one node with a modest wall time (the intended time of your session)
233 and then allocating many small single-node dask-worker jobs with shorter wall
234 times (perhaps 30 minutes) that can easily squeeze into extra space in the job
235 scheduler. As you need more computation, you can add more of these single-node
236 jobs or let them expire.
237
238
239 Use Dask to co-launch a Jupyter server
240 --------------------------------------
241
242 Dask can help you by launching other services alongside it. For example, you
243 can run a Jupyter notebook server on the machine running the ``dask-scheduler``
244 process with the following commands
245
246 .. code-block:: python
247
248 from dask.distributed import Client
249 client = Client(scheduler_file='scheduler.json')
250
251 import socket
252 host = client.run_on_scheduler(socket.gethostname)
253
254 def start_jlab(dask_scheduler):
255 import subprocess
256 proc = subprocess.Popen(['/path/to/jupyter', 'lab', '--ip', host, '--no-browser'])
257 dask_scheduler.jlab_proc = proc
258
259 client.run_on_scheduler(start_jlab)