Visual Studio Code - nthu-ioa/cluster GitHub Wiki
This page describes how to setup VS code for remote development or data analysis.
Basically, this tutorial follows the description from here.
- Latest version of VS Code on your local machine
- Latest version of the "Remote Development" extension pack
- Add the following lines to the ssh config file on your local machine (~/.ssh/config) and replace with your username:
Host cica
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
HostName fomalhaut.astr.nthu.edu.tw
ForwardX11 yes
ForwardX11Trusted yes
User <name>
Host cica_jobs
ProxyCommand ssh cica "nc \$(squeue --me --name=vscode --states=R -h -O NodeList,Comment)"
StrictHostKeyChecking no
User <name>
- Connect to the CICA cluster (fomalhaut) and create the following sbatch file into your home directory (
~/tunnel.sbatch
):
#!/bin/bash -x
#SBATCH -J vscode
#SBATCH -o tunnel
#SBATCH -p mem
#SBATCH -N 1
#SBATCH --ntasks-per-node=4
#SBATCH --mem-per-cpu=4gb
#SBATCH --time=4:00:00
export OMP_NUM_THREADS=4
export XDG_RUNTIME_DIR="/cluster/home/<your_user_name>/.conda/envs/<your_env_name>"
module load python
source activate <your_env_name>
# find open port
PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
scontrol update JobId="$SLURM_JOB_ID" Comment="$PORT"
# start sshd server on the available port
echo "Starting sshd on port $PORT"
/usr/sbin/sshd -D -p ${PORT} -f /dev/null -h ${HOME}/.ssh/id_rsa
Note that you might want to change the number of cores to use in --ntasks-per-node=4
and export OMP_NUM_THREADS=4
.
Here I assume you have your python conda virtual environment name <your_env_name>
ready for your calculations.
Note: you could also modify the tunnel job script to use cpu
or gpu
nodes.
- In the terminal on your local machine, generate an ssh key if you don't have one already using the following:
ssh-keygen -t rsa
- Copy your local public ssh key to the cluster using:
ssh-copy-id cica
-
From your local terminal, connect to the cluster using ssh cica and once logged in, type
sbatch tunnel.sbatch
to start the remote server. Make sure that your job does run! -
Open VS Code on your local machine and connect to your projects using "Remote Explorer" with "cica_jobs" as the ssh target.