<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Keerti Prem Gadde on Medium]]></title>
        <description><![CDATA[Stories by Keerti Prem Gadde on Medium]]></description>
        <link>https://medium.com/@keerti.prem.gadde?source=rss-4d5fb6e0747d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*g3w5F57_Spbq37d1</url>
            <title>Stories by Keerti Prem Gadde on Medium</title>
            <link>https://medium.com/@keerti.prem.gadde?source=rss-4d5fb6e0747d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 14:32:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@keerti.prem.gadde/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SLURM Essentials]]></title>
            <link>https://medium.com/@keerti.prem.gadde/slurm-essentials-16876c6aad77?source=rss-4d5fb6e0747d------2</link>
            <guid isPermaLink="false">https://medium.com/p/16876c6aad77</guid>
            <category><![CDATA[job-scheduling]]></category>
            <category><![CDATA[cluster-computing]]></category>
            <category><![CDATA[slurm]]></category>
            <category><![CDATA[high-performace-computing]]></category>
            <category><![CDATA[linux-commands]]></category>
            <dc:creator><![CDATA[Keerti Prem Gadde]]></dc:creator>
            <pubDate>Sat, 12 Oct 2024 18:27:53 GMT</pubDate>
            <atom:updated>2024-10-12T20:55:39.777Z</atom:updated>
            <content:encoded><![CDATA[<h3>SLURM Essentials: Cluster Computing Commands</h3><h3>Table of Contents</h3><ol><li><a href="#09cd">Introduction</a></li><li><a href="#881b">Setting Up VS Code for Remote Cluster Access</a></li><li><a href="#d083">Basic Linux Commands for Cluster Navigation</a></li><li><a href="#7e68">Understanding SLURM</a></li><li><a href="#b6d5">SLURM Commands in Detail: srun, salloc and sbatch</a></li><li><a href="#67a0">Managing Conda Environments on a Cluster</a></li><li><a href="#1ac3">Advanced SLURM Features and Job Management</a></li><li><a href="#cd7b">Job States in SLURM</a></li><li><a href="#f1f3">Debugging and Troubleshooting</a></li><li><a href="#5566">Data Management and File Transfers</a></li><li><a href="#01ce">Best Practices and Tips</a></li></ol><h3>1. Introduction</h3><p><strong>SLURM</strong> (Simple Linux Utility for Resource Management) is a powerful job scheduling system designed to allocate and manage resources on <strong>High-Performance Computing</strong> (HPC) clusters. Whether you’re training machine learning models, running simulations, or performing large-scale data analysis, SLURM ensures efficient access to essential computing resources.</p><p>In this guide, we’ll walk you through the essentials of using SLURM, from connecting to a cluster with <strong>Visual Studio Code </strong>(VS Code) to running and managing jobs with essential SLURM commands like srun, salloc, and sbatch. We’ll also cover how to set up and manage your environments using <strong>Conda</strong> and optimize your workflow for cluster tasks. Ready to get started? Let’s dive in!</p><h3>2. Setting Up VS Code for Remote Cluster Access</h3><p>Connecting VS Code to a remote cluster provides a seamless environment where you can edit, manage files, and run jobs — all within one interface. Here’s how to get started:</p><h4>Steps for Connecting VS Code to a Cluster:</h4><ol><li><strong>Install the “Remote — SSH” Extension<br></strong> The first step is to install the “Remote — SSH” extension in VS Code. It’s quick and easy: just a couple of clicks, and you’re ready to go!</li><li><strong>Connect to the Cluster<br></strong>Press Ctrl+Shift+P to open the command palette in VS Code, then type: &gt; Remote-SSH: Connect to Host…<br>Enter your cluster’s SSH connection string (e.g., username@cluster-address), and you&#39;ll be prompted to enter your password to finish the connection.</li><li><strong>Optimize with SSH Config File<br></strong>To simplify future connections, you can set up an SSH config file. This will allow you to connect faster without re-entering the connection string each time. Here’s how: <br>On <strong>Windows</strong>, create or edit the file located at:<br>C:\Users\YourUsername\.ssh\config<br>On <strong>Linux/Mac</strong>, use:<br>~/.ssh/config<br>Add the following lines, replacing the placeholders (clustername, cluster-address, and your-username) with your actual details:</li></ol><pre>Host clustername<br>  HostName cluster-address<br>  User your-username</pre><p>Once connected, VS Code will open a terminal where you can access files and run Linux commands on the remote system.</p><p>Alternatively, you can use the command line to open VS Code connected to the remote cluster:</p><pre>code --remote ssh-remote+clustername /home/your-username/your-project-folder</pre><p>💡 <strong>Note:</strong> Once connected, the integrated terminal in VS Code will use Bash, as you’re now interacting with the Linux-based cluster environment — not the Windows command prompt.</p><h3>3. Basic Linux Commands for Cluster Navigation</h3><p>Before diving into SLURM, it’s essential to familiarize yourself with some basic Linux commands for navigating the cluster environment:</p><ul><li>pwd: Print your current directory.</li></ul><pre>pwd<br>/home/username</pre><ul><li>ls: List files and directories.</li></ul><pre>ls -l<br>total 16<br>drwxr-xr-x 3 username group 4096 Sep 30 16:16 Cluster<br>-rw-r--r-- 1 username group 1481 Sep 20 20:12 commands.txt</pre><ul><li>cd: Change to a different directory.</li></ul><pre>cd ProjectFolder</pre><ul><li>mkdir: Create a new directory.</li></ul><pre>mkdir NewProject</pre><ul><li>cp: Copy files or directories.</li></ul><pre>cp source_file.txt destination_folder/</pre><ul><li>mv: Move or rename files.</li></ul><pre>mv old_name.txt new_name.txt</pre><ul><li>rm: Remove files or directories (be cautious with this!).</li></ul><pre>rm unnecessary_file.txt<br>rm -r unnecessary_directory</pre><h3>4. Understanding SLURM</h3><p>SLURM helps manage and schedule jobs on your cluster by assigning resources such as nodes, memory, and GPUs to your tasks. Here’s a quick breakdown of key terms:</p><ul><li><strong>Nodes</strong>: The individual computers in the cluster.</li><li><strong>Partitions</strong>: Groups of nodes with similar properties.</li><li><strong>Jobs</strong>: The tasks you submit to the cluster.</li><li><strong>Job Steps</strong>: Subsections of a job that can run in parallel.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AqX0TYSbNxp7-_-LgQ3Ggg.png" /><figcaption><strong>Figure 1</strong>: SLURM job submission: from login to resource allocation. Source: <a href="https://ashki23.github.io/cluster.html">ashki23.github.io</a></figcaption></figure><p><strong>Checking Available Resources</strong></p><ul><li>To check the available GPUs on the cluster:</li></ul><pre>sinfo -o &quot;%n %G&quot;</pre><ul><li>For detailed information on CPUs, memory, and other features, use:</li></ul><pre>sinfo -o &quot;%n %G %c %m %f&quot;</pre><p><strong>Viewing Jobs in the Queue</strong></p><ul><li>To view all jobs currently in the queue:</li></ul><pre>squeue</pre><ul><li>For a personalized view of your jobs in the queue:</li></ul><pre>squeue -u your_username</pre><ul><li>Filtering Jobs by Job ID with squeue :</li></ul><pre>squeue -j &lt;job_id&gt;</pre><h3>5. SLURM Commands: srun, salloc, and sbatch</h3><p>Let’s dive into the essential SLURM commands and how to use them.</p><ul><li><strong>srun: </strong>Running Parallel Jobs or Interactive Sessions.<br>Use srun for running interactive jobs or short tasks that need immediate resource allocation.<br><strong>Syntax:</strong> srun [options] <br><strong>Example:</strong></li></ul><pre>srun -n 2 --gres=gpu:V100:1 --mem=20G --time 0-1:0:0 python test_script.py</pre><p>This command requests:</p><ul><li><strong>2 CPU cores</strong> (-n 2)</li><li><strong>1 V100 GPU</strong> (--gres=gpu:V100:1)</li><li><strong>20GB of memory</strong> (--mem=20G)</li><li><strong>1 hour of runtime</strong> (--time 0-1:0:0)</li></ul><p><strong>Instructions:</strong></p><ol><li>Navigate to the directory containing your script.</li><li>Run the srun command in the VS Code terminal as shown above.</li><li>The job runs immediately, with output displayed in the terminal.</li></ol><p>💡 <strong>Note:</strong> srun does not generate separate log files; output appears directly in the terminal.</p><ul><li><strong>salloc: </strong>Allocating Resources for Interactive Use.<strong><br></strong>Use salloc for interactive sessions, debugging, or real-time testing of complex, long-running tasks.<br><strong>Syntax: </strong>salloc [options]<br><strong>Example:</strong></li></ul><pre>salloc -n 2 --gres=gpu:V100:1 --mem=20G --time 2-0</pre><p><strong>Instructions:</strong></p><ol><li>Run the salloc command in the VS Code terminal.</li><li>Once resources are allocated, a new shell prompt will appear.</li><li>Load necessary modules and activate your environment:</li></ol><pre>module load anaconda3/latest<br>. $ANACONDA_HOME/etc/profile.d/conda.sh<br>conda activate my_environment</pre><p>4. Run your commands or scripts interactively:</p><pre>python my_script.py</pre><p>5. After finishing, type exit to release the resources.</p><p>💡 <strong>Note: </strong>salloc allocates resources but doesn’t run a job directly. Instead, it provides an interactive shell where you can manually run commands and scripts. Make sure to exit the session once you&#39;re done to release the allocated resources.</p><ul><li><strong>sbatch: </strong>Submitting Batch Jobs.<strong><br></strong>Use sbatch for long-running jobs or tasks that don&#39;t require interaction.<br><strong>Syntax: </strong>sbatch [options] script_file<br><strong>Example script (run_on_cluster.sh):</strong></li></ul><pre>#!/bin/bash<br>#SBATCH -t 5-0:00:00              # set maximum time for the job (5 days)                    <br>#SBATCH --mem=60G                 # allocate 60GB of memory<br>#SBATCH -J my_job                 # name the job &quot;my_job&quot;<br>#SBATCH -n 2                      # request 2 CPU cores<br>#SBATCH --gres=gpu:V100:1         # request 1 V100 GPU<br>#SBATCH --output=output_%j.log    # direct standard output to file with job ID<br>#SBATCH --error=error_%j.log      # direct standard error to file with job ID<br><br>module load anaconda3/latest<br>. $ANACONDA_HOME/etc/profile.d/conda.sh<br>conda activate my_environment<br><br># Install packages from requirements.txt if needed<br>pip install -r requirements.txt<br><br>python my_long_running_script.py</pre><p><strong>Instructions:</strong></p><ol><li>Create the batch script as shown above.</li><li>In the VS Code terminal, submit the job:</li></ol><pre>sbatch run_on_cluster.sh</pre><p>3. SLURM will return a job ID. Use the job ID to monitor the job’s progress.</p><p>For sbatch jobs, output and error logs are generated automatically based on the #SBATCH directives in your script. In the example above:</p><ul><li>Standard output will be in output_[jobID].log</li><li>Error output will be in error_[jobID].log</li></ul><p>You can view these files using commands like cat, less, or open them directly in VS Code.</p><p>💡 <strong>Note: </strong>You can monitor the progress of <strong>sbatch</strong> jobs using commands like squeue or scontrol with the job ID.</p><h3>6. Managing Conda Environments on a Cluster</h3><p>Conda environments can be used consistently across different SLURM jobs (sbatch, srun, salloc). Here’s how to manage them:</p><ul><li>Create a New Environment:</li></ul><pre>conda create -n my_env python=3.8</pre><ul><li>Activate an Environment:</li></ul><pre>conda activate my_env</pre><ul><li>Install packages individually:</li></ul><pre>conda install numpy pandas scikit-learn</pre><ul><li>Or use a requirements.txt file to list package names and versions:</li></ul><pre>pip install -r requirements.txt</pre><ul><li>List All Environments:</li></ul><pre>conda env list</pre><ul><li>Remove an Environment:</li></ul><pre>conda env remove -n my_env</pre><p>💡 <strong>Note:</strong> Always activate your Conda environment in both job scripts and interactive sessions to ensure that the correct environment is being used.</p><h3>7. Advanced SLURM Features and Job Management</h3><ul><li><strong>Job Arrays<br></strong>Submit multiple similar jobs using job arrays. Each job is assigned a unique ID accessible via $SLURM_ARRAY_TASK_ID:</li></ul><pre>#SBATCH --array=1-10</pre><ul><li><strong>Job Dependencies<br></strong>Set dependencies between jobs to create workflows. The following ensures next_job.sh runs only after job 12345 completes successfully:</li></ul><pre>sbatch --dependency=afterok:12345 next_job.sh</pre><ul><li><strong>Resource Monitoring<br></strong>Use these commands to monitor resource usage:</li></ul><pre>scontrol show job &lt;job_id&gt;<br>sacct -j &lt;job_id&gt; --format=JobID,JobName,MaxRSS,Elapsed</pre><h3>8. Job States in SLURM</h3><p>SLURM jobs go through several states during their lifecycle. Here’s a quick overview of the different states:</p><ul><li><strong>Pending</strong>: The job is waiting for resources.</li><li><strong>Running</strong>: The job is actively executing.</li><li><strong>Suspended</strong>: The job is temporarily paused.</li><li><strong>Completed</strong>: The job has finished executing successfully.</li><li><strong>Cancelled</strong>: The job was cancelled by the user or admin.</li><li><strong>Failed</strong>: The job ended with an error.</li><li><strong>Node Fail</strong>: A node failure caused the job to fail.</li><li><strong>Timeout</strong>: The job exceeded its allocated time and was stopped.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*fnOgCvB9KXCnDTcaRB2_Fg.jpeg" /><figcaption><strong>Figure 2</strong>: Slurm stages for a job. Source: <a href="https://en.wikipedia.org/wiki/Slurm_Workload_Manager">Wikipedia</a></figcaption></figure><h3>9. Debugging and Troubleshooting</h3><ul><li><strong>Common SLURM Errors<br></strong>1. Out_OF_MEMORY: Increase memory with the --mem flag.<br>2. Invalid account/partition: Check partition and account permissions.</li></ul><pre># Example to increase memory allocation<br>--mem=80G</pre><pre># Example to check partition<br>scontrol show partition</pre><ul><li><strong>Job Notifications<br></strong>To receive email updates on job statuses (start, end, failure), add this line to your job script:</li></ul><pre>#SBATCH --mail-type=ALL</pre><ul><li><strong>Monitoring Job Status<br></strong>Use scontrol to check the status of a job and troubleshoot issues:</li></ul><pre>scontrol show job &lt;job_id&gt;</pre><h3>10. Data Management and File Transfers</h3><p>Use scp or rsync to transfer files between your machine and the cluster:</p><pre>scp local_file username@cluster:/path/on/cluster<br>rsync -avz local_directory/ username@cluster:/path/on/cluster/</pre><p>For large datasets, compress them before transfer using tar:</p><pre>tar -czf archive.tar.gz folder_to_compress/</pre><h3>11. Best Practices and Tips</h3><ul><li><strong>Accurately Specify Resource Requirements:</strong> Always provide precise resource requests to avoid over- or under-allocation.</li><li><strong>Use Job Arrays for Similar Jobs:</strong> Efficiently submit multiple similar jobs using job arrays.</li><li><strong>Monitor Resource Usage:</strong> Continuously track your job’s resource consumption and adjust future resource requests as needed.</li><li><strong>Keep Conda Environments Minimal:</strong> Maintain project-specific, lean conda environments to prevent conflicts.</li><li><strong>Use Version Control:</strong> Manage your scripts and job files using version control systems like Git.</li><li><strong>Check Job Logs:</strong> Always review output and error log files for sbatch jobs to monitor progress and debug issues.</li></ul><h3><strong>Further Reading and Resources</strong></h3><ul><li><a href="https://slurm.schedmd.com/">SLURM Workload Manager Documentation</a></li><li><a href="https://code.visualstudio.com/docs/remote/ssh">Visual Studio Code: Remote Development using SSH</a></li><li><a href="https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html">Getting started with conda</a></li><li><a href="https://en.wikipedia.org/wiki/Slurm_Workload_Manager">Wikipedia.org/wiki/Slurm_Workload_Manager</a></li><li><a href="https://ashki23.github.io/cluster.html">Introduction to using clusters by Ashkan Mirzaee</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16876c6aad77" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>