-
Notifications
You must be signed in to change notification settings - Fork 1
/
presentation.Rmd
604 lines (409 loc) · 14.5 KB
/
presentation.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
---
title: "Parallelization and Remote Servers"
author: "Abby Bratt, Maria Kuruvilla, and Colin Okasaki"
date: "February 5, 2020"
output:
ioslides_presentation:
incremental: yes
widescreen: yes
header-includes:
- \usepackage{tikz}
- \usepackage{pgfplots}
- \usepackage{verbatim}
- \usepackage{textcomp}
- \usetikzlibrary{shapes,arrows}
---
<!-- General Outline: -->
<!-- Colin (30m) - Intro to how a computer works and some parallelization exercises -->
<!-- Maria (30m) - Walk through an example on the SEFS servers -->
<!-- Abby (30m) - Walk through an example on Hyak -->
# Remote Servers: Why Bother?
<!-- I (Abby) think it would be good to say something about code profiling also -->
<!-- And thinking through when your code is memory intensive vs. cpu intensive, how a computer works, etc -->
## The Basics: How Do Computers Work?
- Computation: CPUs
- Each CPU has 1 or more cores
- Each core can do 1 computation at a time
- Theoretical top speed = all cores active
- Reality: cores need to communicate
- Memory: RAM vs. not-RAM
- RAM is volatile, extremely fast, low-volume
- Hard drive (ex. SSD) is persistent, fairly slow, high-volume
- Sidenote: GPUs and CUDA
- Each GPU holds 100s or 1000s of ''CUDA cores''
- Each CUDA core is very small
- Very fast for ''embarassingly parallel'' problems
## ''Why is my code so slow''
- The most common cases are:
- You've run out of RAM
- Your computer just has too many operations to do
- ''How do I make it faster''
- Run it on a bigger computer with more RAM
- Run it on a bigger computer with more cores
- Solution: use a remote server!
## ''Why is my code still so slow''
Before you use a remote server:
- Do some back-of-the-envelope math
- Make sure you don't need an EB of RAM or an EFLOP
- Sidenote: Units
- kilo, mega, giga (\(10^9\)), tera (\(10^{12}\)), peta (\(10^{15}\)), exa (\(10^{18}\)), zetta, yotta
- FLOP(S) = floating point operation (per second)
- newish desktop might have 32 GB RAM, 25 GLOPS speed
## (Dis)advantages of parallelization
\(N\) cores may save you time up to a factor of \(N\), but:
- only if you efficiently distribute computation between cores
- only if the programmer-time it takes is relatively small
- Sequential computation: the bane of parallel computation
- Communication: the real bane of parallel computation
- Pre-emptive optimization: the bane of all computation
## Example: Conjugate Gradient Descent {.build}
Suppose you wish to calculate \(y = Ax\) but \(A = 10^5 \times 10^5\)
Roughly speaking, \(A\) requites about \(10^{10}\) bytes or 10 GB RAM
Moreover, you need to do \(10^{10}\) multiplications or 10 GFLOPs
Not so bad, but say you want to do this \(10^6\) times (\(\approx\) 6 days)
Luckily \(y_i = \sum A_{ij}x_j\) is independent of all other rows of \(A\)
Calculating \(y_i\) \(\approx\) 10kB, 10 kFLOPs, GPU takes \(\approx\) 15 minutes
Application: conjugate gradient descent to solve \(Ax = b\)
## Recap: Why use a remote server?
- Lots of CPUs (often a few GPUs) available
- Doesn't slow down your personal computer
- Feel like a pro, brag to your friends
## Review
- When should you parallelize?
- When should you definitely not parallelize?
- When should you use a remote server?
## Practice
- MCMC
- Bootstrap
- Likelihood evaluation
- Optimization
# How to Access the QERM/SEFS Servers
## Some specs
- 3 servers
- Pilchuk
- Skykomish
- Snoqualmie
- 24 cores
- 256 GB RAM
- 1 TB of disk space for temporary storage
## MAC
- Microsoft Remote Desktop Connection
- Enter computer/connection name e.g Pilchuck
- PC name e.g. pilchuck.sefs.uw.edu
- Enter your netid and password
- Off campus
- download Husky OnNet from [UWare](https://itconnect.uw.edu/connect/uw-networks/about-husky-onnet/use-husky-onnet/terms-conditions/)
- Open BIG-IP Edge Client
- Connect
## Windows
- Remote Desktop Connection
- Enter computer (snoqualmie.sefs.uw.edu)
- Enter your netid and password
- Off campus
- download Husky OnNet from [UWare](https://itconnect.uw.edu/connect/uw-networks/about-husky-onnet/use-husky-onnet/terms-conditions/)
- Open BIG-IP Edge Client
- Connect
## Linux
- Launch Remmina (or similar software)
- Make sure it is set to RDP (to connect to Windows based desktop)
- Enter Name of server
- Enter Server
- Enter Domain - NETID
- Enter your netid and password
- Off campus
- download Husky OnNet from [UWare](https://itconnect.uw.edu/connect/uw-networks/about-husky-onnet/use-husky-onnet/terms-conditions/)
- Use Firefox to install the f5vpn software on Linux systems
## Navigating
- Go to [https://github.com/aebratt/qermserver-hyak-tutorial]
- Open Git bash
- cd Downloads
- git clone https://github.com/aebratt/qermserver-hyak-tutorial.git
- Open parallel_computing.R
# A Basic R Program
## Parallel computing
- Using this [website](https://nceas.github.io/oss-lessons/parallel-computing-in-r/parallel-computing-in-r.html)
- Use dataset iris
- Sample randomly from these 100 points
- Run a generalised linear model to see if Species is a function of Sepal.length
- Save coefficients of model
- Repeat 10000 times
## Parallel Computing
```{r}
head(iris,10)
```
## Load packages
```{r, eval = TRUE}
library(parallel)
library(doParallel)
library(foreach)
```
## Using doParallel
```{r, eval = TRUE}
numCores <- detectCores()
numCores
registerDoParallel(numCores)
x <- iris[which(iris[,5] != "setosa"), c(1,5)]
trials <- 10000
system.time({
r <- foreach(icount(trials), .combine=rbind) %dopar% {
ind <- sample(100, 100, replace=TRUE)
result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
coefficients(result1)
}
})
```
## Without doParallel
```{r, eval = TRUE}
system.time({
r <- foreach(icount(trials), .combine=rbind) %do% {
ind <- sample(100, 100, replace=TRUE)
result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
coefficients(result1)
}
})
```
## Using lapply()
```{r, eval = TRUE}
x <- iris[which(iris[,5] != "setosa"), c(1,5)]
trials <- seq(1, 10000)
boot_fx <- function(trial) {
ind <- sample(100, 100, replace=TRUE)
result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
r <- coefficients(result1)
res <- rbind(data.frame(), r)
}
system.time({
results <- lapply(trials, boot_fx)
})
```
## Using mclapply()
```{r, eval = TRUE}
x <- iris[which(iris[,5] != "setosa"), c(1,5)]
trials <- seq(1, 10000)
boot_fx <- function(trial) {
ind <- sample(100, 100, replace=TRUE)
result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
r <- coefficients(result1)
res <- rbind(data.frame(), r)
}
system.time({
results <- mclapply(trials, boot_fx, mc.cores = 1)
})
```
## Summary
- We should all parallelize (some times)
- Advantages
- Easy to learn how to use
- Lots of cores and RAM
- Disadvantages
- No GPU
- New softwares get installed once a month during maintenance
# How to Access Hyak
<!-- Outline: -->
<!-- 1. What is hyak? -->
<!-- 2. How does hyak work? -->
<!-- 3. How to log in -->
<!-- 4. How to upload files -->
<!-- 5. How to write a batch script (things you submit to slurm) -->
<!-- 6. How to submit a job -->
<!-- 6bonus - wait, what if I need a special library or piece of software? -->
<!-- 7. How to check what's happening in the queue -->
<!-- 8. How to download finished results -->
<!-- 9. How to game slurm (requesting memory, etc strategically so you get high priority) -->
<!-- 10. Where do get help doing things more advanced than this (multinode stuff, working in languages that need to be compiled, etc) -->
## What is hyak?
Hyak is a word in Chinook Jargon, meaning "fast." Chinook Jargon is the trade language of the Pacific Northwest, incorporating terms from Chinook and Chehalis and other local languages, as well as French and English. We've chosen words from Chinook Jargon for the names of systems in the UW research cyber infrastructure to emphasize their role in supporting the broad range of UW research users and our ties to our place between the mountains and Salish Sea.
--UW IT Connect
## What is hyak?
Hyak is part of an integrated, scalable, scientific super-computing infrastructure operated by UW-IT. It includes the lolo tapearchive system, a high-performance research network, **the Hyak compute infrastructure (the HPC clusters)**, and any scientific support services on making this useful in your research workflows.
--UW IT Connect
## How does hyak work?
Within hyak, **mox** is a supercomputing **cluster**.
A **cluster** is a set of connected computers, **nodes**, that work together in a single system.
In general, **clusters** are faster and more capable than a single computer or even several disconnected computers.
--UW Research Computing Club
## How does hyak work?
On mox, labs or groups can buy groups of nodes called **partitions**. The Research Computing Club applied for a big grant from the Student Technology Fee fund (that we all pay into every quarter!) to purchase nodes accessible to all students.
<!-- If you want to vote on how these dollars get allocated, you can submit proposals or endorse others' proposals on the uwstf website https://uwstf.org/proposals/2020/21 -->
## How does hyak work?
* In general, the compute nodes have the following specs:
- 28 cores
- 128 GB RAM
* The STF partition is currently 92 regular nodes, plus some interactive and GPU nodes.
* That's a lot
## How does hyak work?
<!-- structure goes here -->
* Login nodes (mox1, mox2)
* Have internet
* Use these to upload/download files and submit jobs
* They are slow so __don't__ do heavy processing
* Build nodes (n#####)
* Have internet
* Don't get to take a whole node (so also kinda slow)
* Just for compiling software
* Compute nodes (n#####)
* No internet
* Where your jobs run
## Visually, this looks like:
<div class="centered">
![](images/Hyak_architecture.png){width=500px}
</div>
## How do I log in?
All nodes share the same file system.
Open a terminal window. Type
```
```
Follow two-factor authentication instructions.
You're in!
## It should look like this...
<div class="centered">
![](images/Hyak_successful_login.png){width=600px}
</div>
<!-- Only works if you have access to Hyak, of course! -->
## Exercise
Log in!
## Important locations
* /gscratch/stf
* Main work location for stf users
* Any files untouched for >30 days will be scrubbed!!
* /usr/lusers/<username>
* Home directory
* Only 10 GB of storage per user
* /tmp
* Node local storage
## How do I upload files?
From GitHub:
```
git clone https://github.com/aebratt/qermserver-hyak-tutorial.git
```
From your computer:
```
scp filename [email protected]:/path/to/destination/directory
```
## Exercise
Clone the git repo for this class to **your** scratch directory
## Exercise
Clone the git repo for this class to **your** scratch directory
**Hint:**
From login
```
cd /gscratch/stf
mkdir ./UWNETID
cd ./UWNETID
git clone https://github.com/aebratt/qermserver-hyak-tutorial.git
cd REPO-NAME
```
**Bonus:**
Why use the scratch directory?
## What is a batch script?
* Place to:
- Define all the options for a job you submit to the queue
- Set up environment (e.g. load modules)
- Run!
* Syntax:
- Comment using ##
- Set option using #SBATCH
## How do I write a batch script?
Short answer: don't.
Modify a template! Here's one:
```
vim Hyak_simple_batch.sh
```
Or open this file in your favorite text editor
## It should look like this...
<div class="centered">
![](images/Hyak_simple_batch.png){width=600px}
</div>
## Exercise
Submit a job to the queue!
## Exercise
Submit a job to the queue!
**Hint:**
First, open vim or another text editor and replace UWNETID in Hyak_simple_batch.sh
```
cd /gscratch/stf/UWNETID/qermserver-hyak-tutorial
sbatch -p stf -A stf Hyak_simple_batch.sh
```
## Wait, what if I need some special library or software?
You can do that! For R libraries,
```
mkdir /gscratch/stf/UWNETID/rpackages
srun -p build --time=2:00:00 --mem=10G --pty /bin/bash
```
We just created a directory for storing installed packages and got a session on an **interactive** build node.
## Wait, what if I need some special library or software?
Open the command line
```
module load r_3.6.0
module list
R
install.packages("PACKAGENAME", lib="/gscratch/stf/UWNETID/rpackages")
```
Choose a mirror somewhere on the west coast and press enter.
## Exercise
Submit a more complicated job to the queue!
**Hint:**
First, open vim or another text editor and replace UWNETID in Hyak_complicated.R and Hyak_complicated_batch.sh
```
exit
cd /gscratch/stf/UWNETID/qermserver-hyak-tutorial
sbatch -p stf -A stf Hyak_complicated_batch.sh
```
## When will my jobs run?
See the whole stf partition queue this way:
```
squeue -p stf
```
See just your jobs this way:
```
squeue -p stf -u UWNETID
```
You can also try:
```
sstat -j JOBID-RUNNING
sacct -j JOBID-COMPLETED
```
## Oops, I made a mistake!
Cancel jobs with
```
scancel JOBID#
```
## My job finished! How do I download my results?
From Hyak to GitHub:
```
git add filename
git commit -m "informative commit message"
git push
```
From Hyak to your computer:
```
scp [email protected]:/path/to/file .
```
## How can I get higher priority?
You can check the priority of queued jobs with
```
sprio -p stf
```
How to interpret?
It may look something like
<div class="centered">
![](images/Hyak_priority.png){width=600px}
</div>
## How can I get higher priority?
* **TRES**: Trackable RESources (TRES) are things like cpu, memory, nodes. The more a given TRES Type is requested/allocated on a job, the greater the job priority will be for that job. Mox cares about cpu (i.e. high CPU gets high priority)
* **Fair-share**: The fair-share component to a job's priority influences the order in which a user's queued jobs are scheduled to run based on the portion of the computing resources they have been allocated and the resources their jobs have already consumed. High priority to under-serviced accounts.
* Do not specify a walltime way longer than your job needs.
* Specify your memory! For 128G nodes use --mem=120G or less. The operating system requires some.
## What else can I do?
* Use the checkpoint queue - run your code on other groups' unused resources
* Install and build new software
## Where do I get help?
If you have trouble or you want to do more advanced stuff, check out
```
man SLURMCOMMAND
```
If all else fails, try
* Research Computing Club
* eScience Institute
* UW IT