Saltar a contenido

Interfaz gráfica remota


Uso de scripts

Copie el script correspondiente a su carpeta de trabajo y envíelo a cola. Puede modificar la cantidad de recursos solicitados según su necesidad.

Una vez que lo haya enviado a cola y entre a correr (si hay recursos disponibles), el script creará el archivo slurm-XXXXX.out, donde XXXXX va a ser sustituido por el <JobID>. Dentro de este archivo encontrará un texto similar a este:

==================================================================
JupyterLab is RUNNING on compute node: cn001
------------------------------------------------------------------
STEP 1: Open a terminal on YOUR HOME COMPUTER and run this tunnel:

    ssh -N -L 9491:cn001:9491 hpc.user@172.16.24.2

STEP 2: Leave that terminal open. Open your browser and go to:

    http://localhost:9491/lab?token=1Bwio2ICiZRK68Kgiic0lo7l1u8HJ
==================================================================

Debe seguir las instrucciones:

  1. Copiar este comando en una terminal nueva y dejarla abierta por la duración del job:

    ssh -N -L 9491:cn001:9491 hpc.user@172.16.24.2

  2. Abrir en cualquier navegador la dirección:

    http://localhost:9491/lab?token=1Bwio2ICiZRK68Kgiic0lo7l1u8HJ
    

Lista de scripts

Se pueden ejecutar los siguientes programas remotamente en el cluster mediante su interfaz gráfica:

JupyterLab/CPU

#!/bin/bash -l
#SBATCH --job-name=JupyterLab
#SBATCH --cpus-per-task=8
#SBATCH --time=01:00:00
#SBATCH --partition=shared

# Configuration
USER_NAME=$USER
LOGIN_NODE="172.16.24.2" 
NODE_NAME=$(hostname) 
SRUN="srun --exact -n 1 -c $SLURM_CPUS_PER_TASK"

# Generate a random port between 8000 and 9999 to avoid user conflicts
PORT=$(shuf -i 8000-9999 -n 1)

# Define your custom fixed token (no spaces)
MY_TOKEN=$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 8)

echo "=================================================================="
echo "JupyterLab is RUNNING on compute node: ${NODE_NAME}"
echo "------------------------------------------------------------------"
echo "STEP 1: Open a terminal on YOUR HOME COMPUTER and run this tunnel:"
echo ""
echo "    ssh -N -L ${PORT}:${NODE_NAME}:${PORT} ${USER_NAME}@${LOGIN_NODE}"
echo ""
echo "STEP 2: Leave that terminal open. Open your browser and go to:"
echo ""
echo "    http://localhost:${PORT}/lab?token=${MY_TOKEN}"
echo "=================================================================="

# Launch JupyterLab with the custom token
mamba activate
$SRUN jupyter-lab --no-browser --port=${PORT} --ip=0.0.0.0 --ServerApp.token="${MY_TOKEN}"

JupyterLab/GPU

#!/bin/bash -l
#SBATCH --job-name=JupyterLab
#SBATCH --cpus-per-task=4
#SBATCH --time=01:00:00
#SBATCH --partition=gpu-mig            # Target your MIG partition
#SBATCH --gres=gpu:a100_2g.20gb:1      # Request 1 GPU instance

# Configuration
USER_NAME=$USER
LOGIN_NODE="172.16.24.2" 
NODE_NAME=$(hostname)
SRUN="srun --exact -n 1 -c $SLURM_CPUS_PER_TASK"

# Generate a random port between 8000 and 9999 to avoid user conflicts
PORT=$(shuf -i 8000-9999 -n 1)

# Define your custom fixed token (no spaces)
TOKEN=$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 8)

echo "=================================================================="
echo "JupyterLab (A100 GPU) is RUNNING on compute node: ${NODE_NAME}"
echo "------------------------------------------------------------------"
echo "STEP 1: Open a terminal on YOUR HOME COMPUTER and run this tunnel:"
echo ""
echo "    ssh -N -L ${PORT}:${NODE_NAME}:${PORT} ${USER_NAME}@${LOGIN_NODE}"
echo ""
echo "STEP 2: Leave that terminal open. Open your browser and go to:"
echo ""
echo "    http://localhost:${PORT}/lab?token=${TOKEN}"
echo "=================================================================="

# Launch JupyterLab with the custom token
mamba activate
$SRUN jupyter-lab --no-browser --port=${PORT} --ip=0.0.0.0 --ServerApp.token="${TOKEN}"

MatLab

#!/bin/bash
#SBATCH --job-name=matlab_vnc
#SBATCH --time=04:00:00            # Adjust as needed
#SBATCH --cpus-per-task=4         # Adjust based on your MATLAB workload
#SBATCH --mem=16G                  # Adjust based on your MATLAB workload
#SBATCH --partition=shared         # Replace with your cluster's partition name

# 1. Fix Perl Locale Warnings
export LC_ALL=C
export LANG=C
export APPTAINERENV_MLM_LICENSE_FILE="27000@172.16.48.89"

# 2. Pick a random VNC display number between 100 and 999
DISPLAY_NUM=$(shuf -i 100-999 -n 1)
PORT=$((5900 + DISPLAY_NUM))
NODE=$(hostname)
SRUN="srun --exact -n 1 -c $SLURM_CPUS_PER_TASK"

# 3. Generate a random 8-character password for this specific session
VNC_PASS=$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 8)

mkdir -p ~/.vnc
echo "${VNC_PASS}" | vncpasswd -f > ~/.vnc/passwd
chmod 600 ~/.vnc/passwd

# 4. Start the VNC server on the compute node
vncserver :${DISPLAY_NUM} -geometry 1920x1080 -depth 24

# 5. Print tunnel instructions to the Slurm output log
echo "=================================================================="
echo "MATLAB GUI is starting on compute node: $NODE"
echo "------------------------------------------------------------------"
echo ""
echo "STEP 1: Run this SSH tunnel command in a NEW LOCAL TERMINAL:"
echo "    ssh -N -L ${PORT}:${NODE}:${PORT} ${USER}@172.16.24.2"
echo ""
echo "STEP 2: Open your VNC Viewer and connect to:"
echo "    localhost:${PORT}"
echo ""
echo "    PASSWORD FOR THIS SESSION: ${VNC_PASS}"
echo "=================================================================="

# 6. Set the display and license variables
export DISPLAY=:${DISPLAY_NUM}
# export MLM_LICENSE_FILE=27000@your.license.server.edu # Replace with your license server

# 7. Run MATLAB inside Singularity
# -B binds your cluster storage so you can access your files
$SRUN apptainer exec -B /scratch -B /home \
    /opt/ohpc/pub/containers/matlab/matlab.sif \
    matlab -desktop

# 8. Clean up: kill the VNC server when MATLAB is closed
vncserver -kill :${DISPLAY_NUM}

Paraview

#!/bin/bash
#SBATCH --job-name=paraview
#SBATCH --time=04:00:00
#SBATCH --cpus-per-task=8         
#SBATCH --partition=shared         
export LC_ALL=C
export LANG=C

DISPLAY_NUM=$(shuf -i 100-999 -n 1)
vncserver :${DISPLAY_NUM} -geometry 1920x1080
export DISPLAY=:${DISPLAY_NUM}

PORT=$((5900 + DISPLAY_NUM))
NODE=$(hostname)
SRUN="srun --exact -n 1 -c $SLURM_CPUS_PER_TASK"
CONTAINER="/opt/ohpc/pub/containers/paraview-6.1.1.sif"

VNC_PASS=$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 8)
mkdir -p ~/.vnc
echo "${VNC_PASS}" | vncpasswd -f > ~/.vnc/passwd
chmod 600 ~/.vnc/passwd

echo "=================================================================="
echo "ParaView GUI is starting on compute node: $NODE"
echo "------------------------------------------------------------------"
echo ""
echo "STEP 1: Run this SSH tunnel command in a NEW LOCAL TERMINAL:"
echo "    ssh -N -L ${PORT}:${NODE}:${PORT} ${USER}@172.16.24.2"
echo ""
echo "STEP 2: Open your VNC Viewer and connect to:"
echo "    localhost:${PORT}"
echo ""
echo "    PASSWORD FOR THIS SESSION: ${VNC_PASS}"
echo "=================================================================="

$SRUN $CONTAINER paraview

vncserver -kill :${DISPLAY_NUM}

R + JupyterLab

Para correr R es necesario tener instalado Miniforge3 previamente. Una vez realizado este paso se procede a instalar RStudio:

mamba install -c conda-forge r-base r-irkernel -y

Una vez instalado puede proceder a usar el script de cola de JupyterLab/CPU o JupyterLab/GPU y le aparecerá la opción de ejecutar código de R.


RStudio

#!/bin/bash -l
#SBATCH --job-name=RStudio
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --time=01:00:00
#SBATCH --partition=shared

# --- Configuration ---
LOGIN_NODE="172.16.24.2"
NODE_NAME=$(hostname)
PORT=$(shuf -i 8000-9999 -n 1)
PASSWORD=$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 8)
SRUN="srun --exact -n 1 -c $SLURM_CPUS_PER_TASK"

# Ensure you have built the image at this path: /opt/ohpc/pub/containers/rstudio_latest.sif
CONTAINER_IMAGE="/opt/ohpc/pub/containers/rstudio-4.6.1.sif"

# --- Environment Setup ---
export APPTAINERENV_PASSWORD=$PASSWORD

# Create isolated temporary directories for this specific job
TMP_DIR="/tmp/${USER}_rstudio_${SLURM_JOB_ID}"
mkdir -p "$TMP_DIR/run"
mkdir -p "$TMP_DIR/lib"
mkdir -p "$TMP_DIR/tmp"
mkdir -p "$TMP_DIR/db"

# Create required RStudio database configuration
cat <<EOF > $TMP_DIR/db/rstudio-os.sqlite
EOF
echo "provider=sqlite" > $TMP_DIR/db/database.conf
echo "directory=/var/lib/rstudio-server/db" >> $TMP_DIR/db/database.conf

# Generate secure cookie key
uuidgen > $TMP_DIR/run/secure-cookie-key 2>/dev/null || echo "c23f8b10-6c9f-4318-bc1a-$(date +%s)" > $TMP_DIR/run/secure-cookie-key
chmod 0600 $TMP_DIR/run/secure-cookie-key

# Cleanup function to run when the job ends (or is cancelled)
trap "rm -rf $TMP_DIR" EXIT

# --- Output Instructions for User ---
echo "=================================================================="
echo "RStudio Server is RUNNING on compute node: ${NODE_NAME}"
echo "------------------------------------------------------------------"
echo "STEP 1: Run this tunnel command on your local machine:"
echo ""
echo "    ssh -N -L ${PORT}:${NODE_NAME}:${PORT} ${USER}@${LOGIN_NODE}"
echo ""
echo "STEP 2: Open your browser and go to:"
echo ""
echo "    http://localhost:${PORT}"
echo "------------------------------------------------------------------"
echo "Username: ${USER}"
echo "Password: ${PASSWORD}"
echo "=================================================================="

# --- Launch RStudio ---
    $SRUN apptainer exec \
        --bind $TMP_DIR/run:/var/run/rstudio-server \
        --bind $TMP_DIR/lib:/var/lib/rstudio-server \
        --bind $TMP_DIR/db:/var/lib/rstudio-server/db \
        --bind $TMP_DIR/tmp:/tmp \
        $CONTAINER_IMAGE \
        rserver --www-port ${PORT} \
                --auth-none=0 \
                --auth-pam-helper-path=pam-helper \
                --secure-cookie-key-file=/var/run/rstudio-server/secure-cookie-key \
                --database-config-file=/var/lib/rstudio-server/db/database.conf \
                --server-user ${USER}

Visual Studio Code

#!/bin/bash -l
#SBATCH --job-name=VSCode
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --time=04:00:00
#SBATCH --partition=shared

# Configuration
USER_NAME=$USER
LOGIN_NODE="172.16.24.2"
NODE_NAME=$(hostname)
SRUN="srun --exact -n 1 -c $SLURM_CPUS_PER_TASK"

# Generate a random port between 8000 and 9999 to avoid user conflicts
PORT=$(shuf -i 8000-9999 -n 1)

# Define your custom fixed password (no spaces)
MY_PASSWORD=$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 8)

echo "=================================================================="
echo "VS Code Server is RUNNING on compute node: ${NODE_NAME}"
echo "------------------------------------------------------------------"
echo "STEP 1: Open a terminal on YOUR HOME COMPUTER and run this tunnel:"
echo ""
echo "    ssh -N -L ${PORT}:${NODE_NAME}:${PORT} ${USER_NAME}@${LOGIN_NODE}"
echo ""
echo "STEP 2: Leave that terminal open. Open your browser and go to:"
echo ""
echo "    http://localhost:${PORT}"
echo ""
echo "    (When prompted, enter password: ${MY_PASSWORD})"
echo "=================================================================="

# Launch code-server with the custom password
module load vscode/latest

export PASSWORD="${MY_PASSWORD}"
$SRUN code-server --bind-addr 0.0.0.0:${PORT} --auth password --disable-telemetry

IMPORTANTE!!!

Debe de matar el job (scancel) cuando termine de usar el VSCode.

puntosHPC_0.svg