-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-cluster-setup.qmd
299 lines (202 loc) · 10.7 KB
/
04-cluster-setup.qmd
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
# Cluster Setup {#sec-cluster-setup}
Within this chapter, we will cover establishing a workspace on the Campus Cluster. Workspace setup usually requires about 5 different steps.
- Ensure the cluster can easily be accessed from a local computer.
- Enable command shortcuts through aliases.
- Setup a GitHub access token for pulling software in from private repositories (skip if not needed).
- Create a space on a project drive for where R packages should be installed.
- Install *R* packages!
## Secure Shell (SSH) Setup
For accessing a cluster from command line, **Secure Shell (SSH)** is preferred. Access to the cluster requires typing out each time:
``` bash
ssh netid@cc-login.campuscluster.illinois.edu
# password
```
Connecting in this manner is tedious since it involves repetitively typing out login credentials. There are two tricks that void the necessity to do so. Effectively, we have:
- Passwordless login
- Public/Private SSH Keys
- Alias connection names
- SSH Config
Thus, instead of entering a password, the local computer can submit a private key to be verified by a server. Not only is this more secure, but it avoids the hassle of remembering the password and typing it out while observers watch. Secondly, the connection alias will allow for typing:
``` bash
ssh icc
```
Not bad eh?
### Generating an SSH Key
On your **local** computer, open up Terminal and type:
``` bash
## Run:
ssh-keygen -t rsa -C "netid@illinois.edu"
## Respond to:
# Enter file in which to save the key (/home/demo/.ssh/id_rsa): # [Press enter]
# Enter passphrase (empty for no passphrase): # Write short password
```
### Copy SSH Key to Server
Next, let's copy the generated key from your **local** computer onto the cluster.
``` bash
## Run:
ssh-copy-id netid@cc-login.campuscluster.illinois.edu
```
On macOS, prior to using `ssh-copy-id`, the command will need to be installed. [`Homebrew`](https://brew.sh/) provides a formula that will setup the command. Install using:
``` bash
# Install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# Install the required command binary
brew install ssh-copy-id
```
### SSH Config File
Inside of `~/.ssh/config`, add the following host configuration. Make sure to **replace** `<netid>` value with your personal netid.
``` bash
Host icc
HostName cc-login.campuscluster.illinois.edu
User netid
```
**Note:** This assumes a default location is used for the SSH key. If there is a custom SSH key location add `IdentityFile ~/.ssh/sshkeyname.key` after the `User` line.
## Bash Aliases
Bash has the ability to create command aliases through `alias`. The primary use is to take long commands and create short-cuts to avoid typing them. Alternatively, this allows one to also rename commonly used commands. For example, one could modify the `ls` command to always list each file and show all hidden files with:
``` bash
alias ls='ls -la'` .
```
We suggest creating a `~/.bash_aliases` on the cluster and filling it with:
``` bash
--8<-- "config/.bash_aliases"
```
You may download this directly onto the cluster using:
``` bash
wget https://raw.githubusercontent.com/coatless/hpc/master/docs/config/.bash_aliases
```
To ensure bash aliases are available, we need to add the file to `~/.bashrc`:
``` bash
--8<-- "config/.bashrc"
```
**Note:** the load modules component is shown
You may download this directly onto the cluster using:
``` bash
rm -rf ~/.bashrc
wget https://raw.githubusercontent.com/coatless/hpc/master/docs/config/.bashrc
```
## Optional: GitHub Personal Access Token (PAT)
We briefly summarize the process for getting and registering a [GitHub Personal Access Token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) in *R*.
[![PAT Token Walkthrough Video](https://img.youtube.com/vi/c14aqVC-Szo/0.jpg)](https://www.youtube.com/watch?v=c14aqVC-Szo)
The token may be created at: <https://github.com/settings/tokens>
From there, we can add it to the *R* session with:
``` bash
touch ~/.Renviron
cat << EOF >> ~/.Renviron
GITHUB_TOKEN="your_github_token_here"
GITHUB_PAT="your_github_token_here"
EOF
```
Alternatively, within *R*, the token can be added by typing:
``` r
file.edit("~/.Renviron")
```
Then, writing in the configuration file:
``` bash
GITHUB_TOKEN="your_github_token_here"
GITHUB_PAT="your_github_token_here"
```
## Default *R* Package Storage Location
*R*'s default library directory where packages are installed into is found within the user's home directory at:
``` bash
# location for R 3.6.z
/home/$USER/R/x86_64-pc-linux-gnu-library/3.6
# location for R 4.0.z
/home/$USER/R/x86_64-pc-linux-gnu-library/4.0
# location for R 4.1.z
/home/$USER/R/x86_64-pc-linux-gnu-library/4.1
```
Installing packages into the default location is problematic because any files placed within a user's home directory count against the directory's space quota (for limits, please see @sec-cluster-storage). As *R* packages can take a considerable amount of space when installed, the best course of action is to change the default library directory. Therefore, *R* packages should be either stored in a project directory or a purchased space allocation on the cluster that an investor may purchase.
The path to an investor's space is given as:
``` bash
/projects/<investor>/shared/$USER
```
Frequently, the cluster staff will create a symlink into the investor's directory once authorization is given. In the case of **Statistics**, the investor name is `stat`, so the directory would be either:
``` bash
/projects/stat/shared/$USER
# or the symlink version:
~/project-stat/
```
In any case, we recommend creating and registering an `r-pkgs` directory under the appropriate project space. The registration with *R* is done using the [`R_LIBS_USER` variable](https://stat.ethz.ch/R-manual/R-patched/library/base/html/libPaths.html) in [`~/.Renvion`](https://stat.ethz.ch/R-manual/R-patched/library/base/html/Startup.html).
``` bash
# Setup the .Renviron file in the home directory
touch ~/.Renviron
# Append a single variable into the Renvironment file
cat << 'EOF' >> ~/.Renviron
# Location to R library
R_LIBS_USER=~/project-stat/R/%p-library/%v
EOF
# Construct the path
Rscript -e 'dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)'
```
Under this approach, we have move the location of the default package directory to:
``` bash
~/project-stat/R/%p-library/%v
# the expanded version of %p and %v give:
~/project-stat/R/x86_64-pc-linux-gnu-library/x.y
```
**Note:** After each minor *R* version upgrade of R x.y, you will need to recreate the package storage directory using:
``` r
Rscript -e 'dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)'
```
One question that arises:
> Why not set up a generic personal library directory called `~/Rlibs`?
We avoided a generic name for two reasons:
1. New "major" releases of *R* -- and sometime minor versions -- are incompatible with the old packages.
2. Versioning by number allows for graceful downgrades if needed.
In the case of the first bullet, its better to start over from a new directory to ensure clean builds.
Though, you could opt not to and remember:
``` r
update.packages(ask = FALSE, checkBuilt = TRUE)
```
## Install *R* packages into library
Prior to installing an *R* package, make sure to load the appropriate *R* version with:
``` r
module load R/x.y.z
```
where `x.y.z` is a supported version number, e.g. `module load R/4.1.1_sandybridge` will make available *R* 4.1.1 that works on any cluster node.
Once *R* is loaded, packages can be installed by entering into *R* or directly from bash. The prior approach will be preferred as it mimics local *R* installation procedures while the latter approach is useful for one-off packages installations.
Enter into an interactive *R* session from bash by typing:
``` bash
R
```
Then, inside of *R*, the package installation may be done using:
``` r
# Install a package
install.packages('remotes', repos = 'https://cloud.r-project.org')
# Exit out of R and return to bash.
q(save = "no")
```
Unlike the native *R* installation route, installing packages under bash uses the `Rscript` command and requires writing the install command as a string:
``` bash
Rscript -e "install.packages('remotes', repos = 'https://cloud.r-project.org')"
```
Be careful when using quotations to specify packages. For each of these commands, we begin and end with `"` and, thus, inside the command we use `'` to denote strings. With this approach, escaping character strings is avoided.
### Installing Packages into Development Libraries
If you need to use a different library path than what was setup as the default, e.g. `~/project-stat/r-libs`, first create the directory and, then, specify a path to it with `lib = ''` in \`install.packages().
``` bash
mkdir -p ~/project-stat/devel-pkg
Rscript -e "install.packages('remotes', lib = '~/project-stat/devel-pkg',
repos = 'https://cloud.r-project.org/')"
```
### Installing Packages from GitHub
For packages stored on GitHub, there are two variants for installation depending on the state of the repository. If the repository is **public**, then the standard `install_github("user/repo")` may be used. On the other hand, if the repository is **private**, the package installation call must be accompanied by a [**GitHub Personal Access Token**](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) in the `auth_token=''` parameter of `install_github()`. In the prior step, if the `~/.Renviron` contains `GITHUB_PAT` variable, there is no need to specify in the `install_github()` call as it will automatically be picked up.
```r
# Install package from GitHub
Rscript -e "remotes::install_github('coatless/visualize')"
# Install from a private repository on GitHub
Rscript -e "remotes::install_github('stat447/netid', auth_token = 'abc')"
```
### Parallelized package installation
By default, all users are placed onto the login nodes. Login nodes are configured for staging and submitting jobs *not* for installing software. The best practice and absolute fastest way to install software is to use an **interactive job**. Interactive jobs place the user directly on a compute node with the requested resources, e.g. 10 CPUs or 5GB of memory per CPU.
Before installing multiple *R* packages, we recommend creating an interactive job with:
``` bash
srun --cpus-per-task=10 --pty bash
```
Once on the interactive node, load the appropriate version of *R*:
``` r
module load R/x.y.z # where x.y.z is the version number
```
From here, make sure every package installation call uses the `Ncpus =` parameter set equal to the number of cores requested for the interactive job.
``` r
Rscript -e "install.packages('remotes', repos = 'https://cloud.r-project.org', Ncpus = 10L)"
```