-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
435 lines (382 loc) · 13 KB
/
index.html
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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
@import url(http://fonts.googleapis.com/css?family=Rambla:400,700,400italic,700italic);
@import url(http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400,700);
@import url(stack.css);
@import url(style.css);
@import url(highlight.js/styles/monokai.css);
.big {
font-size: 128px;
}
.caption {
font-size: 96px;
text-align: center;
text-shadow: 0px 2px 6px rgba(0,0,0,.5);
}
</style>
<body class="overview">
<section>
<h1 class="title">Scientific computing on the<br/>
Harvard <em class="title">Odyssey</em><br/> cluster</h1>
<h2 class="author">Gábor Csárdi</h2>
<h2 class="email">[email protected]</h2>
</section>
<section>
<h2>Goals and outline</h2>
<ol class="outline">
<li>Introduce the Odyssey cluster
<li>Pointers to get documentation and help
<li>Show you an example project
<li>Tips on how to make good use of Odyssey
</ol>
</section>
<section>
<h2>At the end of this talk you should be able to</h2>
<ol class="outline">
<li>log in to Odyssey,
<li>copy files to and/from Odyssey,
<li>create a simple R project,
<li>run it on Odyssey, and
<li><span class="em">get help</span> if you are stuck.
</ol>
</section>
<!-- --------------------------------------------------- -->
<section>
<h1 class="title">The Odyssey cluster</h1>
</section>
<section>
<h1 class="title">Research Computing website</h1>
<h1 class="title"><a href="https://rc.fas.harvard.edu">
<code>https://rc.fas.harvard.edu</code></a></h1>
</section>
<section>
<h2>Special Odyssey rules for you</h2>
<ul>
<li>You have an account set up (FIXME)
<li>Use the <code>serial_requeue</code> or <code>stats</code>
partition
<li>Use the <code>/n/regal/stats</code> scratch space
<li>Use <code>/scratch</code> for temporary space (fast!)
<li>If you run R, you usually do not need more than one core.
(Unless you do something on top of MPI.)
</ul>
</section>
<section>
<h2>Important rules and tips</h2>
<ul>
<li>Do not run computation on login nodes.
<li>Do not submit tens of thousands of jobs.
<li>Do not submit you jobs in the last minute to get
homework results. They <span class="em">will fail</span>
for the first submission. If they do not fail for the
fifth submission or so, then you are very good!
(Also, there might not be enough resources available
to run everybody's last minute jobs.)
<li>Test on a "regular" computer (on your laptop).
<li>Test on an interactive job.
<li>Submit 1-2 jobs first, to see if they work. If they seem
to be running, then submit the rest. Or cancel the test jobs
and resubmit.
</ul>
</section>
<section>
<h2>Tip: easier login and file transfer</h2>
<p>
On OSX and Linux. Put this into your <code>~/.ssh/config</code> file
on your laptop/desktop (not on odyssey!):
<pre class="code">
Host odyssey.fas.harvard.edu odyssey ody
Hostname odyssey.fas.harvard.edu
User csardi
ControlMaster auto
ControlPath /tmp/%r@%h:%p
ForwardAgent yes
ForwardX11Trusted yes
</pre>
</p>
<p>
After this, you only need to authenticate yourself at
your first login. Until you close this first session,
other sessions don't need your password and verification key.
</p>
<p>
Plus, you can use <code>ody</code> instead full odyssey hostname.
</p>
</section>
<section>
<h2>Tip: module system and R</h2>
<p>
<ul>
<li>Support for various software packages is modular on odyssey.
<li>If you want to use a piece of software, you need to load
its module:
<pre class="code">
rclogin09:~$ module load centos6/R-3.1.1
Loading module hpc/intel-mkl-11.0.0.079.
Loading module centos6/tcl-8.5.14.
Loading module centos6/tk-8.5.14.
Loading module centos6/fftw-3.3_gcc-4.4.7.
Loading module centos6/gsl-1.16_gcc-4.4.7.
Loading module centos6/hdf5-1.8.11_gcc-4.4.7.
Loading module centos6/netcdf-4.3.0_gcc-4.4.7.
Loading module centos6/R-3.1.1.</pre>
<li>Dependencies are handled automatically.
<li>List all modules with <code>module avail 2>&1 | less</code>
<li>Type in <code>module</code> without arguments to list the
available options.
<li>Put module loads in your <code>~/.bashrc</code> file.
<span class="em">Needed for Rscript!</span>
</ul>
</p>
</section>
<section>
<h2>Tip: your R packages</h2>
<ul>
<li>You can have your own library of R packages
<li>Set an R mirror site in <code>~/.Rprofile</code>:
<pre class="code">options(repos = structure(c(CRAN = "http://cran.rstudio.com")))</pre>
<li>Just simply start installing them.
<li>You can use the <code>devtools</code> package to
install R packages directly from Github.
</ul>
</section>
<!-- --------------------------------------------------- -->
<section>
<h1 class="title">Getting help</h1>
</section>
<section>
<h1 class="title">This tutorial @
<span class="url"><a href="https://github.com/airoldilab/odyssey">
https://github.com/airoldilab/odyssey</a></span></h1>
</section>
<section>
<h1 class="title"><a href = "https://rc.fas.harvard.edu/">
Harvard RC web pages</a></h1>
<h1 class="title">SLURM manual</h1>
<h1 class="title">rchelp email / ticket</h1>
</section>
<!-- --------------------------------------------------- -->
<section>
<h1 class="title">Example project: <br>
Pearson correlation of noisy variables</h1>
</section>
<section>
<h2>Create R package</h2>
<ul>
<li>Easiest with <code>devtools::create</code>.
<li>Register an account on Github and put your package
there.
<li>Use git to install it on Odyssey.
</ul>
</section>
<section>
<h2>R package directories</h2>
<pre class="filelist">
stat221 <span class="em"># R package for all code</span>
├─DESCRIPTION <span class="em"># package meta data</span>
├─NAMESPACE <span class="em"># don't need to touch it, usually</span>
├─R <span class="em"># R code files</span>
│ ├─util.R <span class="em"># Common for all projects</span>
│ ├─hw1-1.R
│ └─...
├─data <span class="em"># data files (small)</span>
│ ├─hw1.rda
│ └─...
└─inst
└─tests
└─testthat
└─test-hw1.R
</pre>
</section>
<section>
<h2>Setting up a git repository on <span class="url">
<a href="http://github.com">github.com</a></span></h2>
<ul>
<li>Helps to keep files and changes under control.
<li>Helps to copy files to Odyssey and back
<li>Easier to fix bugs.
<li>Simplifies collaboration.
<li>Issue tracker to make a TODO list.
</ul>
</section>
<!-- --------------------------------------------------- -->
<section>
<h1 class="title">More Odyssey and R tips</h1>
</section>
<section>
<h2>Interactive jobs</h2>
With a trick, we can reserve a processor for interactive
work, and can detach and (re-)attach to the job.
<pre class="code"><code class="bash"><span class="prompt">[csardi@rclogin03 ~]$</span> <span
class="input">screen bash</span>
<span class="prompt">[csardi@rclogin03 ~]$</span> <span
class="input">srun -n 1 -p interact --pty R</span>
srun: job 833346 queued and waiting for resources
srun: job 833346 has been allocated resources
R version 3.0.1 (2013-05-16) -- "Good Sport"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
[...]
</code></pre>
Now we can detach by pressing <code>CTRL+a d</code>, and log out from
the cluster completely. To reattach, login to the same interactive
node:
<pre class="code"><code class="bash"><span class="prompt">[csardi@rclogin05 ~]$</span> <span class="input">ssh rclogin03</span>
<span class="prompt">[csardi@rclogin03 ~]$</span> <span class="input">screen -r</span>
</code></pre>
See <code>man screen</code> for the details.
</section>
<section>
<h2>Memory requirements</h2>
<a label="memory"></a>
<ul>
<li>Slurm needs to know how much memory your job needs.
<li>This is somewhat a pain, because it is often hard to judge.
<li>Always specify the size of requested memory for <code>srun</code>
and <code>sbatch</code>, because the default is 100MB only.
<li>Tip: in R use <code>gc()</code> to measure the required memory,
in a trial run, after your program finished:
<pre class="code"><code class="R">> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 181400 9.7 407500 21.8 350000 18.7
Vcells 276264 2.2 786432 6.0 786332 6.0
> a <- numeric(10^8)
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 181405 9.7 407500 21.8 350000 18.7
Vcells 100276271 765.1 110892011 846.1 100436297 766.3
</pre></code>
<li>Take the sum of the last column.
</ul>
</section>
<section>
<h2>Put code and SLURM commands in the same R file</h2>
<pre class="code"><code class="R">#! /usr/bin/env Rscript
#SBATCH -n 1 # (Max) number of tasks per job, for R usually 1
#SBATCH -o out.txt # File for the standard output
#SBATCH -e err.txt # File for the standard error
#SBATCH --open-mode=append # Append to standard output and error files
#SBATCH -p serial_requeue # Partition to use
#SBATCH --mem-per-cpu=4096 # Memory required per CPU, in MegaBytes
#SBATCH --mail-user=<user> # Where to send mail
#SBATCH --mail-type=ALL # When to send mail
noisy_cor <- function(num_genes, true_cor, noise_var) {
## do the computation
...
## write results to file
...
}
noisy_cor(5000, 0.9, 0.1, to_file = TRUE)
</code></pre>
</section>
<section>
<h2>Put SLURM Rscript files in your R package</h2>
<pre class="code"><code class="R">#! /usr/bin/env Rscript
#SBATCH -n 1 # (Max) number of tasks per job, for R usually 1
#SBATCH -o out.txt # File for the standard output
#SBATCH -e err.txt # File for the standard error
#SBATCH --open-mode=append # Append to standard output and error files
#SBATCH -p serial_requeue # Partition to use
#SBATCH --mem-per-cpu=4096 # Memory required per CPU, in MegaBytes
#SBATCH --mail-user=<user> # Where to send mail
#SBATCH --mail-type=ALL # When to send mail
## Check if we are running from SLURM
if (Sys.getenv("SLURM_JOB_ID") != "") {
library(stat221)
noisy_cor(5000, 0.9, 0.1, to_file = TRUE)
}
</code></pre>
In another file:
<pre class="code"><code class="R">noisy_cor <- function(num_genes, true_cor, noise_var, to_file = FALSE) {
## do the computation
...
if (to_file) {
## write results to file
...
}
}
</code></pre>
</section>
<section>
<h2>Job arrays</h2>
<p>Often, we want to run the same program, with different
paremeters. This can be done two ways with SLURM.</p>
<p>We generate the submission files with a program (maybe from R), as
many submission files as the number of jobs we want to run, and then
submit each of them to an individual job.</p>
</section>
<section>
<h2>Job arrays</h2>
Better: use SLURM job arrays:
<pre class="code"><code class="R">#! /usr/bin/env Rscript
#SBATCH -n 1 # (Max) number of tasks per job, for R usually 1
#SBATCH -o out-%a.txt # File for the standard output
#SBATCH -e err-%a.txt # File for the standard error
#SBATCH -p serial_requeue # Partition to use
#SBATCH --mem-per-cpu=1024 # Memory required per CPU, in MegaBytes
#SBATCH -a 1-9 # Array of 9 jobs, with ids 1, 2, ..., 9
if (Sys.getenv("SLURM_JOB_ID") != "") {
true_cor <- c(0.5, 0.8, 0.9)
noise_var <- c(0.1, 0.2, 0.5)
params <- expand.grid(true_cor = true_cor, noise_var = noise_var)
my_id <- as.numeric(Sys.getenv("SLURM_ARRAY_TASK_ID"))
my_params <- params[my_id,]
noisy_cor(num_genes = 5000, true_cor = my_params$true_cor,
noise_var = my_params$noise_var, to_file = TRUE)
}
</code></pre>
</section>
<section>
<h2>Tip: how to set the random seed</h2>
<p>Problem: you need a large number of random seeds for the jobs.</p>
<p>Do not set the random seed based on time in seconds!
You need at least milliseconds! Save the seed with the results!</p>
<pre class="code"><code class="R">fracSec <- function() {
now <- as.vector(as.POSIXct(Sys.time())) / 1000
as.integer(abs(now - trunc(now)) * 10^8)
}
...
seed <- fracSec()
set.seed(seed)
...
save(result, seed, file = "...")
</code></pre>
</section>
<section>
<h2>Debugging in R, some tips</h2>
<p><ul>
<li>Use the <code>traceback()</code> function immediately
after an error.
<li>Use the <code>debug()</code> function to step through an R
function line by line.
<li>Use <code>options(error = recover)</code> to enter an interactive
debugging tool, immediately after an error happens.
</ul></p>
</section>
<!-- <section> -->
<!-- <h2>CPU time profiling</h2> -->
<!-- TODO -->
<!-- </section> -->
<!-- <section> -->
<!-- <h2>Memory profiling</h2> -->
<!-- TODO -->
<!-- </section> -->
<section>
<h2 class="title">Even more R tips</h2>
<h2 class="title">
<a href="http://adv-r.had.co.nz/">http://adv-r.had.co.nz/</a>
</h2>
</section>
<script src="http://d3js.org/d3.v2.js?2.7.3"></script>
<script src="stack.v0.js"></script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
MathJax.Hub.Config({
showProcessingMessages: false,
});
</script>
</script>
<script src="highlight.js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>