Welcome to the Google Codelab for running a Slurm cluster on Google Cloud Platform! By the end of this codelab you should have a solid understanding of the ease of provisioning and operating an auto-scaling Slurm cluster.
Google Cloud teamed up with SchedMD to release a set of tools that make it easier to launch the Slurm workload manager on Compute Engine, and to expand your existing cluster dynamically when you need extra resources. This integration was built by the experts at SchedMD in accordance with Slurm best practices.
If you're planning on using the Slurm on Google Cloud Platform integrations, or if you have any questions, please consider joining our Google Cloud & Slurm Community Discussion Group!
Basic architectural diagram of a stand-alone Slurm Cluster in Google Cloud Platform.
Slurm is one of the leading workload managers for HPC clusters around the world. Slurm provides an open-source, fault-tolerant, and highly-scalable workload management and job scheduling system for small and large Linux clusters. Slurm requires no kernel modifications for its operation and is relatively self-contained. As a cluster workload manager, Slurm has three key functions:
1. It allocates exclusive or non-exclusive access to resources (compute nodes) to users for some duration of time so they can perform work.
2. It provides a framework for starting, executing, and monitoring work (normally a parallel job) on the set of allocated nodes.
3. It arbitrates contention for resources by managing a queue of pending work.
If you don't already have a Google Account (Gmail or G Suite), you must create one. Sign-in to Google Cloud Platform console (console.cloud.google.com) and open the Manage resources page:
Click Create Project.
Enter a project name. Remember the project ID (highlighted in red in the screenshot above). The project ID must be a unique name across all Google Cloud projects. If your project name is not unique Google Cloud will generate a random project ID based on the project name.
Next, you'll need to enable billing in the Developers Console in order to use Google Cloud resources.
Running through this codelab shouldn't cost you more than a few dollars, but it could be more if you decide to use more resources or if you leave them running (see "Conclusion" section at the end of this document). The Google Cloud Platform pricing calculator is available here.
New users of Google Cloud Platform are eligible for a $300 free trial.
While Google Cloud can be operated remotely from your laptop, in this codelab we will be using Google Cloud Shell, a command line environment running in the Cloud.
From the GCP Console click the Cloud Shell icon on the top right toolbar:
Then click Start Cloud Shell:
It should only take a few moments to provision and connect to the environment:
This virtual machine is loaded with all the development tools you'll need. It offers a persistent 5GB home directory, and runs on the Google Cloud, greatly enhancing network performance and simplifying authentication. Much, if not all, of your work in this lab can be done with simply a web browser or a Google Chromebook.
Once connected to the cloud shell, you should see that you are already authenticated and that the project is already set to your PROJECT_ID:
$ gcloud auth list
Credentialed accounts: - <myaccount>@<mydomain>.com (active)
$ gcloud config list project
[core] project = <PROJECT_ID>
If the project ID is not set correctly you can set it with this command:
$ gcloud config set project <PROJECT_ID>
Updated property [core/project].
In the Cloud Shell session, execute the following command to clone (download) the Git repository that contains the Slurm for Google Cloud Platform deployment-manager files:
git clone https://github.com/SchedMD/slurm-gcp.git
Switch to the Slurm deployment configuration directory by executing the following command:
In the Cloud Shell session, open the deployment configuration YAML file
slurm-cluster.yaml. You can either use your preferred command line editor (vi, nano, emacs, etc.) or use the Cloud Console Code Editor to view the file contents:
The contents of the file will look like this:
# [START cluster_yaml] imports: - path: slurm.jinja resources: - name: slurm-cluster type: slurm.jinja properties: cluster_name : google1 static_node_count : 2 max_node_count : 10 zone : us-central1-b region : us-central1 cidr : 10.10.0.0/16 controller_machine_type : n1-standard-2 compute_machine_type : n1-standard-2 login_machine_type : n1-standard-2 #login_node_count : 1 # Optional compute configuration fields #cpu_platform : Intel Skylake #preemptible_bursting : False #external_compute_ips : False #private_google_access : True #compute_disk_type : pd-standard #compute_disk_size_gb : 10 #controller_disk_type : pd-standard #controller_disk_size_gb : 100 #login_disk_type : pd-standard #login_disk_size_gb : 10 #nfs_apps_server : #nfs_home_server : #controller_secondary_disk : True #controller_secondary_disk_type : pd-standard #controller_secondary_disk_size_gb : 300 # Optional GPU configuration fields #gpu_type : nvidia-tesla-v100 #gpu_count : 8 #slurm_version : < Current slurm version, e.g. 17.11.8 > default_users : < GCP user email addr, comma separated > # [END cluster_yaml]
This YAML file details the configuration of the deployment, the slurm version to deploy, and the machine instance types to deploy.
Please note that you need to fill in the "default_users" field with the username portion of the email account associated with your GCP account. For example, if you log into GCP using "email@example.com", please fill in "myname" in the "default_users" field.
Within this YAML file there are several fields. These include:
In the Cloud Shell session, execute the following command from the
gcloud deployment-manager deployments create google1 --config slurm-cluster.yaml
This command creates a deployment named slurm. The operation can take a few minutes to complete, so please be patient.
Once the deployment has completed you will see output similar to:
Create operation operation-1515793351850-5629b244a3810-c9541e28-80863bfb completed successfully. NAME TYPE STATE ERRORS INTENT all-internal-firewall-rule compute.v1.firewall COMPLETED  compute1 compute.v1.instance COMPLETED  compute2 compute.v1.instance COMPLETED  controller compute.v1.instance COMPLETED  login1 compute.v1.instance COMPLETED  no-ip-internet-route compute.v1.route COMPLETED  slurm-network compute.v1.network COMPLETED  ssh-firewall-rule compute.v1.firewall COMPLETED 
Follow these steps to view the deployment in Google Cloud Platform Console:
With the deployment's configuration verified let's confirm the cluster's instances are started. In the Cloud Platform Console, in the Products & Services menu, click Compute Engine.
Under VM instances review the four virtual machine instances that have been created by the deployment manager. This includes login1, controller, compute1, and compute2.
Notice that compute1 and compute2 may or may not have external IPs, according to the "external_compute_ips" field in the deployment YAML. If they have no external IPs the compute nodes route their traffic through a NAT gateway in the controller node.
In the Cloud Shell session, click the SSH button next to the login1 instance in Google Cloud Console. Alternatively, execute the following command, substituting <ZONE> for the login1 node's zone:
gcloud compute ssh google1-login1 --zone=<ZONE>
This command logs into the login1 virtual machine.
You're now logged in to your cluster's Slurm login node. This is the node that's dedicated to user/admin interaction, scheduling Slurm jobs, and administrative activity.
Let's run a couple commands to introduce you to the Slurm command line.
Execute the sinfo command to view the status of our cluster's resources:
Sample output of sinfo appears below. sinfo reports the nodes available in the cluster, the state of those nodes, and other information like the partition, availability, and any time limitation imposed on those nodes.
PARTITION AVAIL TIMELIMIT NODES STATE NODELIST debug* up infinite 8 idle~ compute[3-10] debug* up infinite 2 idle compute[1-2]
Since we have allocated two static nodes you see compute1 & compute2 listed as idle. The remaining nodes (compute3 through compute10) are marked as "idle~" (the node is in an idle and non-allocated mode, ready to be bursted to and spun up).
Next, execute the squeue command to view the status of our cluster's queue:
The expected output of squeue appears below. squeue reports the status of the queue for a cluster. This includes each the job ID of each job scheduled on the cluster, the partition the job is assigned to, the name of the job, the user that launched the job, the state of the job, the wall clock time the job has been running, and the nodes that job is allocated to. We don't have any jobs running, so the contents of this command is empty.
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
Let's run a job so we can see Slurm in action and get a job in our queue!
While logged in to login1, use your preferred text editor to create a new file "hostname_batch":
Copy the following text into the file to create a simple sbatch script:
#!/bin/bash # #SBATCH --job-name=hostname_sleep_sample #SBATCH --output=out_%j.txt # #SBATCH --nodes=2 srun hostname sleep 60
This script defines the Slurm options first with the commented, "SBATCH" lines. First, the execution environment is defined as bash. The job name is defined as "hostname_sleep_sample". The output file is set as "output_%j.txt" where %j is substituted for the Job ID according to the Slurm Filename Patterns. This output file is written by each compute node to a local directory, in this case the directory the sbatch script is launched from. In our example this is the user's /home folder, which is a NFS-based shared file system. Finally the number of nodes this script should run on is defined as 2.
After the options are defined the executable commands are provided. This script will run the
hostname command in a parallel manner through the srun command, and sleep for 60 seconds afterwards. You may also try modifying the script to execute a few other commands like
Execute the sbatch script using the sbatch command line:
Running sbatch will return a Job ID for the scheduled job, for example:
Submitted batch job 2
We can use this Job ID to track and manage the job execution and resources. Execute the following command to view the Slurm job queue:
You will likely see the job you executed listed like below:
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) 3 debug hostname username R 0:10 2 compute[1-2]
You can also execute the sinfo command to view the Slurm cluster info:
This will show the nodes listed in squeue in the "alloc" state, marking them as allocated for a job:
PARTITION AVAIL TIMELIMIT NODES STATE NODELIST debug* up infinite 8 idle~ compute[3-10] debug* up infinite 2 alloc compute[1-2]
Once the job is complete, it will no longer be listed in squeue, and the "alloc" nodes in sinfo will return to the "idle" state. The output file out_%j.txt will have been written to your NFS-shared /home folder, and will contain the hostnames. Open or cat the output file (typically out_2.txt), it contents of the output file will contain:
Great work, you've run a job on your Slurm cluster!
Now let's try to auto-scale a cluster. While logged in to login1, open the hostname_batch script we created earlier. Edit the script to change the nodes field to 4 nodes:
This will run the hostname command across 4 nodes, with one task per node, as well as printing the output to the srun.out file. This process will be run in the background to allow us to monitor the cluster as it is scaled.
Since we had 2 nodes already statically provisioned we should see two additional nodes automatically provisioned and added to the slurm cluster. This will take just a few minutes. The automatic nature of this process has two benefits. First, it eliminates the work typically required in a HPC cluster of manually provisioning nodes, configuring the software, integrating the node into the cluster, and then deploying the job. Second, it allows users to save money because idle, unused nodes are scaled down until the minimum number of nodes is running.
While the additional nodes are being provisioned, run sinfo to watch the nodes being allocated:
You can also check the VM instances section in Google Cloud Console to view the newly provisioned nodes. It will take a few minutes to spin up the nodes and get Slurm installed before the job is allocated to the newly allocated nodes.
Monitor squeue until the job has completed and no longer listed:
Once completed open or cat the latest output file (typically out_3.txt) and confirm it ran on compute1-4:
compute1 compute2 compute3 compute4
After being idle for 30 minutes (configurable within slurm.conf's SuspendTime field) the dynamically provisioned compute nodes will be de-allocated to release resources. You can validate this by running sinfo periodically and observing the cluster size fall back to 2.
Congratulations, you've created a Slurm cluster on Google Cloud Platform and used its latest features to auto-scale your cluster to meet workload demand! You can use this model to run any variety of jobs, and it scales to hundreds of instances in minutes by simply requesting the nodes in Slurm.
If you would like to continue learning to use Slurm on GCP, be sure to continue with the "Building Federated HPC Clusters with Slurm" codelab. This codelab will guide you through setting up two federated Slurm clusters in the cloud, to represent how you might achieve a multi-cluster federation, whether on-premise or in the cloud.
Are you building something cool using Slurm's new GCP-native functionality? Have questions? Have a feature suggestion? Reach out to the Google Cloud team today through Google Cloud's High Performance Computing Solutions website, or chat with us in the Google Cloud & Slurm Discussion Group!
Logout of the slurm node:
Let any auto-scaled nodes scale down before deleting the deployment. You can also delete these nodes manually using "gcloud compute instances delete compute[X-Y]", or by using the Console GUI to select multiple nodes and clicking "Delete".
You can easily clean up the deployment after we're done by executing the following command from your Google Cloud Shell, after logging out of login1:
gcloud deployment-manager deployments delete google1
When prompted, type Y to continue. This operation can take some time, please be patient.
To cleanup, we simply delete our project.
If you need support using these integrations in testing or production environments please contact SchedMD directly using their contact page here: https://www.schedmd.com/contact.php
You may also use SchedMD's Troubleshooting guide here: https://slurm.schedmd.com/troubleshoot.html
Finally you may also post your question to the Google Cloud & Slurm Discussion Group found here: https://groups.google.com/forum/#!forum/google-cloud-slurm-discuss
Please submit feedback about this codelab using this link. Feedback takes less than 5 minutes to complete. Thank you!