Skip to content

Instantly share code, notes, and snippets.

@clane9
Last active July 9, 2023 00:26
Show Gist options
  • Save clane9/2e843b708ab77f4f0526b3bf57268adb to your computer and use it in GitHub Desktop.
Save clane9/2e843b708ab77f4f0526b3bf57268adb to your computer and use it in GitHub Desktop.
Running VS code on PSC compute nodes

Running VS code on PSC compute nodes

Here are some quick instructions for running VS code on a PSC/Access/bridges compute node.

Why? It makes your VS Code session faster, and lets you run notebooks within VS Code without guilt.

1. Create an SSH route to the compute node

It's awkward to connect to a compute node through VS code, since you have to go through a login node first. You can make it easier by setting up a new "host" in your ~/.ssh/config file that defines the multi-hop connection.

Open your ~/.ssh/config and add these lines (replacing YOUR_USER_NAME with your user name on PSC).

Host bridges2
    HostName bridges2.psc.edu
    User YOUR_USER_NAME

Host r001
    HostName r001.ib.bridges2.psc.edu
    User YOUR_USER_NAME
    ProxyCommand ssh bridges2 -W %h:%p

Host r002
    HostName r002.ib.bridges2.psc.edu
    User YOUR_USER_NAME
    ProxyCommand ssh bridges2 -W %h:%p

This will add routes for the main login node bridges2, as well as two compute nodes: r001 and r002. These are most common for interactive sessions. If you need to use another node, just add another host.

2. Start an interactive session

Next, start an interactive session. I like to ssh bridges2, then create a screen session (in case my connection drops)

# Start or resume a screen session named "A"
screen -dR A

Then launch an interactive session

# Start an interactive session with 8 CPUs for 2 hours
interact -n 8 -t 2:00:00

Once the interactive session starts, make a note of what node you were assigned. Then you can just sleep inside the terminal (so the scheduler doesn't automatically cancel the job) and minimize the terminal--we won't need it anymore.

# Sleep for 30 secs on repeat
watch sleep 30

3. Start a remote VS code session on the compute node

Now you just need to open a remote VS Code session to the compute node. Open VS Code, click the "Open a Remote window" button in the lower left, select "Connect to Host". You should hopefully see the compute node where your interactive session is running in the dropdown (if not, return to Step 1). Once the session starts, you can open your project as usual.

4. Closing the interactive session (optional)

When you're done, you just close everything in reverse

  • Close the VS Code window
  • Exit the interactive session running in the separate terminal
  • Exit the screen session

If you forget, the interactive session will just run to completion, and then SLURM will kill everything for you.

@clane9
Copy link
Author

clane9 commented Jun 7, 2023

See also this discussion (from @nx10).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment