Running Calculations: Difference between revisions

From bwHPC Wiki
Jump to navigation Jump to search
No edit summary
 
(72 intermediate revisions by 7 users not shown)
Line 1: Line 1:
← This page is used in the [[HPC Glossary]] to explain the term "Batch Scheduler" and "Batch System"
== Description ==
== Life Cycle of a Calculation (Job) ==
[[File:running_calculations_on_cluster.svg|thumb|upright=0.4]]
[[File:running_calculations_on_cluster.svg|thumb|upright=0.4]]
On your desktop computer, you start your calculations and they start immediately, run until they are finished, then your desktop does mostly nothing, until you start another calculation. A compute cluster has several hundred, maybe a thousand computers (compute nodes), all of them are busy most of the time and many people want to run a great number of calculations. So running your job has to include some extra steps:
On your desktop computer you start your calculations and they start immediately, running until they are finished. Then your desktop does mostly nothing, until you start another calculation. A compute cluster has several hundred, maybe a thousand computers (compute nodes), all of them are busy most of the time and many people want to run a great number of calculations. So running your job has to include some extra steps:


# prepare a script (usually a shell script), with all the commands that are necessary to run your calculation from start to finish. In addition to the commands necessary to run the calculation, this ''batch script'' has a header section, in which you specify details like required compute cores, estimated runtime, memory requirements, disk space needed, etc.
# prepare a script (a set commands to run - usually as a shell script), with all the commands that are necessary to run your calculation from start to finish. In addition to the commands necessary to run the calculation, this ''[[batch script]]'' has a header section, in which you specify details like required compute cores (processing units witin a computer), estimated runtime, memory requirements, disk space needed, etc.
# ''Submit'' the script into a queue, where your ''job'' (calculation)
# ''Submit'' the script into a queue, where your ''job'' (calculation)
# Job is queued and waits in row with other compute jobs until the resources you requested in the header become available.
# gets asigned an inital priority, is queued and waits in row with other compute jobs until the resources you requested in the header become available. (Requested time is also a resource!)
# Execution: Once your job reaches the front of the queue, your script is executed on a compute node. Your calculation runs on that node until it is finished or reaches the specified time limit.
# Execution: Once a suitable resource slot is available and your job is in the front of the queue of suitable jobs (suitable with regards to the resource slot), your script is executed on (a) compute node(s). Your calculation runs on that/those node(s) until it is finished or reaches the specified time limit.
# Save results: At the end of your script, include commands to save the calculation results back to your home directory.
# Save results: Include commands to save the calculation results back to a long term storage (e.g. your home directory), at least at the end of your script. What you have not saved until the job finishes won't be saved!
# If your job reaches the specified time limit, all your running processes will be killed and the resources get cleared. So any data that has not been saved will be lost!


There are two types of batch systems currently used on bwHPC clusters, called "Moab" (legacy installs) and "Slurm".
The software that distributes jobs on compute nodes is called a '''[[batch system]]''' or '''batch scheduler'''. The software currently used as a [[batch system]] on bwHPC clusters is "Slurm".


Learn more about the functioning of job distribution in
== Link to Batch System per Cluster ==


→ '''[[batch system]]'''
Because of differences in configuration (partly due to different available hardware), each cluster has their own batch system documention:


== Example Jobs ==
* Slurm systems
**[[bwUniCluster_2.0_Slurm_common_Features|Slurm bwUniCluster 2.0]]
** [[JUSTUS2/Slurm | Slurm JUSTUS 2]]
** [[Helix/Slurm | Slurm Helix]]
* Moab systems (legacy systems with deprecated queuing system)
** [[NEMO/Moab|Moab NEMO specific information]]
** [[BinAC/Moab|Moab BinAC specific information]]


For most software that a bwHPC project installed on the cluster, we have prepared an example job script running some example calculation with that exact software.
== Scaling ==


How to access these examples is described in the "Software job examples" section of the page
When you are running your calculations, you will have to decide on how many compute-cores your calculation will be simultaniously calculated. For this, your computational problem will have to be divided into pieces, which always causes some overhead.


→ '''[[Environment Modules]]'''
How to find a reasonable number of how many compute cores to use for your calculation is described in the page
* [[Scaling]]


== Job Script and Job Submission ==
== Energy Efficiency ==


Batch jobs are submitted with the command:
Please also see our advice for
* [[Energy Efficient Cluster Usage]]


<syntaxhighlight lang="bash">$ sbatch <job-script> </syntaxhighlight>
== HPC Glossary ==


A job script contains options for Slurm in lines beginning with #SBATCH as well as your commands which you want to execute on the compute nodes. For example:
A short definition of the typical elements of an HPC cluster.


<syntaxhighlight lang="slurm">#!/bin/bash
'''HPC Cluster''': Collection of compute nodes with (usually) high bandwidth and low latency communication.
#SBATCH --partition=<cluster specific>
They can be accessed via login nodes.
#SBATCH --ntasks-per-node=8
#SBATCH --time=00:05:00
#SBATCH --mem=1gb
#SBATCH --export=NONE
echo 'Here would start your calculation script'
</syntaxhighlight>


Please see cluster specific examples from the links in the next section, because exact options needed differ by cluster.
'''Node''': An individual computer with one or more sockets, part of an HPC cluster.


== Link to Batch System and Examples per Cluster ==
'''Socket''': Physical socket where the CPU capsules are placed.


Because of differences in configuration (partly due to different available hardware), each cluster has their own batch system documentation:
'''Core''': The physical unit that can independently execute tasks on a CPU.
Modern CPUs generally have multiple cores.


&rarr; '''[[BwUniCluster3.0/Running_Jobs|Slurm bwUniCluster 3.0]]'''
'''Thread''': A logical unit that can be executed independently.
If the same processor core is configured to execute one or more execution paths in parallel it is called '''Hyperthreading''' (a hardware setting).
Alternatively, there can be software threads that can be understood in the context of "parallel execution paths" within the same program (eg. to work through different and independent data arrays in parallel).
This is referred to as '''Multithreading''', eg. via OpenMP.


&rarr; '''[[JUSTUS2/Jobscripts: Running Your Calculations | Slurm JUSTUS 2]]'''
'''CPU''': Central Processing Unit.
It performs the actual computation in a compute node.
A modern CPU is composed of numerous cores and layers of cache.


&rarr; '''[[Helix/Slurm | Slurm Helix]]'''
'''GPU''': Graphics Processing Unit.
GPUs in HPC clusters are used as high-performance accelerators and are particularly useful to process workloads in the fields of Machine Learning (ML) and Artificial Intelligence (AI) more efficiently. The software has to be designed specifically to use GPUs.
CUDA and OpenACC are the most popular platforms in scientific computing with GPUs.


&rarr; '''[[NEMO2/Slurm | Slurm NEMO2]]'''
'''RAM''': Random Access Memory.

It is used as the working memory for the cores.
&rarr; '''[[BinAC2/Slurm | Slurm BinAC2]]'''

== How To Run Jobs Efficiently ==


When you are running your calculations, you will have to decide on how many compute-cores your job will be simultaneously calculated.
For this, your computational problem will have to be divided into pieces, which always causes some overhead.

How to find a reasonable number of how many compute cores to use for your calculation can be found under

&rarr; '''[[Scaling]]'''

Running calculations on an HPC node consumes a lot of energy. To make the most of the available resources and keep cluster and energy use as efficient as possible please also see our advice for

&rarr; '''[[Energy Efficient Cluster Usage]]'''

To optimize the job efficiency, it is very helpful to check which resources a job has actually used.

&rarr; '''[[Job Monitoring]]'''

== Dos and Don'ts ==

There are a number of pitfalls users might encounter when starting to use compute clusters. To avoid some of them, we've collected some best practices in the form of a Dos and Dont's list. It is meant to serve as guidance, not as an absolute imperative, because sometimes stricly avoiding every undesired behaviour is not feasible, though discussing those cases with the cluster operators beforehand is a good idea.

{| style="background:#deffee; width:100%; font-size:100%;"
|'''Dos:'''
* Bundle large amounts of tiny calculations (e.g. 1000 short running analyses taking 2 minutes each) together into fewer / a single job(s) that orchestrates them to run consecutively (and maybe even distributes them among different cores)
* Estimate the total calculation time of your job. A short test run (either on your local machine or on the cluster) can help, though transferability and extrapolation lead to inaccuracies.
:: &rarr; Request a calculation time larger than your estimate. For a new calculation about 20%-30% more time than estimated often is a feasable starting point. Good time estimates are below 10% of extra time requested.
:: &rarr; Having the requested time be close to the actual calculation time is beneficial for the cluster because it helps the scheduler to be more precise and thus shortens idle times.
* Plan early what calculations you want to perform and create a rough timetable for when you want to submit them. Keep cluster waiting times in mind and ideally have some buffer before important deadlines (e.g. paper submission deadlines).
:: &rarr; The scheduler does not know of your urgency and you have no way of communicating your urgency to the scheduler. Therefore the bwHPC recommends to avoid generating the need for urgent calculations. We however also know that sometimes urgency can not be avoided. In such cases contact the cluster operators to see if they can help you out. Don't ask for this lightly, because if everything is urgent, nothing is!
:: &rarr; Many things have a tendency to avoid obliging to plans. Sudden problems can arise both on the user end and on the cluster end, so having a personal time buffer for such cases is good for anxiety prevention.
* Be mindful when performing very long calculations. For a multitude of reasons a computation job may suddenly end during the run. The longer the calculation the higher the risk of an unexpected error.
:: &rarr; If possible create checkpoint files regularly during your calculations, from which you can pick up the calculation again.
* Keep communication bottlenecks in mind when requesting resources.
:: &rarr; With greater physical distance between compute units (cores) comes a longer communication time between them. This leads to efficiency losses depending on the communication volume and frequency.
|}
<br>
{| style="background:#FFCCCC; width:100%; font-size:100%;"
|'''Don'ts:'''<br>
* Do not run very short jobs (single digit minutes) on regular compute nodes. Some clusters offer separate partitions for short running jobs.
:: &rarr; For the sake of efficiency small calculations should use few cores and accept runtimes larger than 1 hour.
:: &rarr; If a parallelizable compute job calculates in under 1 hour on 1 core you should check your reasoning why it needs to run on the cluster at all instead of your local machine. Most (if not all) modern consumer machines do have multiple cores available and often have higher clock speeds than cluster CPUs. The true power of modern compute clusters comes from splitting large parallelizable calculations over many compute cores, usually at the cost of somewhat lower core clock speeds.
* Do not unnecessarily split your calculation into many tiny short running jobs to "trick" the backfilling system by using every 5 minute idle gap that may occur.
:: &rarr; Allocation of a job onto the compute nodes takes up some time for every job, as does cleanup afterwards. Thus by splitting a calculation its overall efficiency decreases accordingly.
:: &rarr; The scheduler assigns and updates priorities and starting times of jobs frequently. A higher number of jobs in the queue means a higher workload for the scheduler, leading to unnecessary strain of the system.
* Do not request resources that remain unused by your job.
:: &rarr; The Resource Management System calculates your recent usage by multiplying the number of requested compute resources (CPU cores / GPUs) by the time the job was allocated. So if 90% of the cores are idle most of the time or not used at all doesn't matter to the system, it will always use 100% of the requested compute resources for the calculation of the Fair Share Value. For the time it however uses the actual allocated time of the jobs instead of what was requested.
:: &rarr; Requesting lots of compute resources for a job usually leads to longer waiting times in the queue compared to less resource intensive jobs.
* Do not spawn too many threads with your jobs. Although multithreading allows some code to run overall more efficient due to better resource usage, spawning too many threads on a compute unit has the contrary effect because the threads have to be managed.
:: &rarr; Be mindful when increasing the thread count and analyse your actual performance gain.
|}

Latest revision as of 11:48, 19 October 2026

← This page is used in the HPC Glossary to explain the term "Batch Scheduler" and "Batch System"

Life Cycle of a Calculation (Job)

Running calculations on cluster.svg

On your desktop computer you start your calculations and they start immediately, running until they are finished. Then your desktop does mostly nothing, until you start another calculation. A compute cluster has several hundred, maybe a thousand computers (compute nodes), all of them are busy most of the time and many people want to run a great number of calculations. So running your job has to include some extra steps:

  1. prepare a script (a set commands to run - usually as a shell script), with all the commands that are necessary to run your calculation from start to finish. In addition to the commands necessary to run the calculation, this batch script has a header section, in which you specify details like required compute cores (processing units witin a computer), estimated runtime, memory requirements, disk space needed, etc.
  2. Submit the script into a queue, where your job (calculation)
  3. gets asigned an inital priority, is queued and waits in row with other compute jobs until the resources you requested in the header become available. (Requested time is also a resource!)
  4. Execution: Once a suitable resource slot is available and your job is in the front of the queue of suitable jobs (suitable with regards to the resource slot), your script is executed on (a) compute node(s). Your calculation runs on that/those node(s) until it is finished or reaches the specified time limit.
  5. Save results: Include commands to save the calculation results back to a long term storage (e.g. your home directory), at least at the end of your script. What you have not saved until the job finishes won't be saved!
  6. If your job reaches the specified time limit, all your running processes will be killed and the resources get cleared. So any data that has not been saved will be lost!

The software that distributes jobs on compute nodes is called a batch system or batch scheduler. The software currently used as a batch system on bwHPC clusters is "Slurm".

Learn more about the functioning of job distribution in

→ batch system

Example Jobs

For most software that a bwHPC project installed on the cluster, we have prepared an example job script running some example calculation with that exact software.

How to access these examples is described in the "Software job examples" section of the page

→ Environment Modules

Job Script and Job Submission

Batch jobs are submitted with the command:

$ sbatch <job-script>

A job script contains options for Slurm in lines beginning with #SBATCH as well as your commands which you want to execute on the compute nodes. For example:

#!/bin/bash
#SBATCH --partition=<cluster specific>
#SBATCH --ntasks-per-node=8 
#SBATCH --time=00:05:00
#SBATCH --mem=1gb
#SBATCH --export=NONE
echo 'Here would start your calculation script'

Please see cluster specific examples from the links in the next section, because exact options needed differ by cluster.

Link to Batch System and Examples per Cluster

Because of differences in configuration (partly due to different available hardware), each cluster has their own batch system documentation:

→ Slurm bwUniCluster 3.0

→ Slurm JUSTUS 2

→ Slurm Helix

→ Slurm NEMO2

→ Slurm BinAC2

How To Run Jobs Efficiently

When you are running your calculations, you will have to decide on how many compute-cores your job will be simultaneously calculated. For this, your computational problem will have to be divided into pieces, which always causes some overhead.

How to find a reasonable number of how many compute cores to use for your calculation can be found under

→ Scaling

Running calculations on an HPC node consumes a lot of energy. To make the most of the available resources and keep cluster and energy use as efficient as possible please also see our advice for

→ Energy Efficient Cluster Usage

To optimize the job efficiency, it is very helpful to check which resources a job has actually used.

→ Job Monitoring

Dos and Don'ts

There are a number of pitfalls users might encounter when starting to use compute clusters. To avoid some of them, we've collected some best practices in the form of a Dos and Dont's list. It is meant to serve as guidance, not as an absolute imperative, because sometimes stricly avoiding every undesired behaviour is not feasible, though discussing those cases with the cluster operators beforehand is a good idea.

Dos:
  • Bundle large amounts of tiny calculations (e.g. 1000 short running analyses taking 2 minutes each) together into fewer / a single job(s) that orchestrates them to run consecutively (and maybe even distributes them among different cores)
  • Estimate the total calculation time of your job. A short test run (either on your local machine or on the cluster) can help, though transferability and extrapolation lead to inaccuracies.
→ Request a calculation time larger than your estimate. For a new calculation about 20%-30% more time than estimated often is a feasable starting point. Good time estimates are below 10% of extra time requested.
→ Having the requested time be close to the actual calculation time is beneficial for the cluster because it helps the scheduler to be more precise and thus shortens idle times.
  • Plan early what calculations you want to perform and create a rough timetable for when you want to submit them. Keep cluster waiting times in mind and ideally have some buffer before important deadlines (e.g. paper submission deadlines).
→ The scheduler does not know of your urgency and you have no way of communicating your urgency to the scheduler. Therefore the bwHPC recommends to avoid generating the need for urgent calculations. We however also know that sometimes urgency can not be avoided. In such cases contact the cluster operators to see if they can help you out. Don't ask for this lightly, because if everything is urgent, nothing is!
→ Many things have a tendency to avoid obliging to plans. Sudden problems can arise both on the user end and on the cluster end, so having a personal time buffer for such cases is good for anxiety prevention.
  • Be mindful when performing very long calculations. For a multitude of reasons a computation job may suddenly end during the run. The longer the calculation the higher the risk of an unexpected error.
→ If possible create checkpoint files regularly during your calculations, from which you can pick up the calculation again.
  • Keep communication bottlenecks in mind when requesting resources.
→ With greater physical distance between compute units (cores) comes a longer communication time between them. This leads to efficiency losses depending on the communication volume and frequency.


Don'ts:
  • Do not run very short jobs (single digit minutes) on regular compute nodes. Some clusters offer separate partitions for short running jobs.
→ For the sake of efficiency small calculations should use few cores and accept runtimes larger than 1 hour.
→ If a parallelizable compute job calculates in under 1 hour on 1 core you should check your reasoning why it needs to run on the cluster at all instead of your local machine. Most (if not all) modern consumer machines do have multiple cores available and often have higher clock speeds than cluster CPUs. The true power of modern compute clusters comes from splitting large parallelizable calculations over many compute cores, usually at the cost of somewhat lower core clock speeds.
  • Do not unnecessarily split your calculation into many tiny short running jobs to "trick" the backfilling system by using every 5 minute idle gap that may occur.
→ Allocation of a job onto the compute nodes takes up some time for every job, as does cleanup afterwards. Thus by splitting a calculation its overall efficiency decreases accordingly.
→ The scheduler assigns and updates priorities and starting times of jobs frequently. A higher number of jobs in the queue means a higher workload for the scheduler, leading to unnecessary strain of the system.
  • Do not request resources that remain unused by your job.
→ The Resource Management System calculates your recent usage by multiplying the number of requested compute resources (CPU cores / GPUs) by the time the job was allocated. So if 90% of the cores are idle most of the time or not used at all doesn't matter to the system, it will always use 100% of the requested compute resources for the calculation of the Fair Share Value. For the time it however uses the actual allocated time of the jobs instead of what was requested.
→ Requesting lots of compute resources for a job usually leads to longer waiting times in the queue compared to less resource intensive jobs.
  • Do not spawn too many threads with your jobs. Although multithreading allows some code to run overall more efficient due to better resource usage, spawning too many threads on a compute unit has the contrary effect because the threads have to be managed.
→ Be mindful when increasing the thread count and analyse your actual performance gain.