Skip to content

How to Edit HPC Job Scripts

Quick Start

  1. Locate the sections you need to modify:
{# Defaults start #}      # System settings
{# Preambles start #}     # Module loading
{# Directives start #}    # Resource allocation
# Your job commands       # Main execution
{# Postambles start #}    # Cleanup

Common Modifications

1. Changing Resource Requests

# CPU cores
{{ sbatch("cpus-per-task", 16) }}

# Memory
{{ sbatch("mem-per-cpu", "4G") }}

# Wall time
{{ sbatch("time", "24:00:00") }}

# GPUs
{{ sbatch("gpus-per-task", 1) }}

2. Input/Output Files

cd {{ inputDir }}                   # Change working directory
-i input.txt -o output.txt          # Specify I/O files

3. MPI/OpenMP Settings

# Number of MPI tasks
{% set tasksPerNode = 4 %}

# OpenMP threads
export OMP_NUM_THREADS=4

Step-by-Step Guide

  1. Backup Your Script
cp job.sh job.sh.backup
  1. Check Resource Settings
  2. Review machine.cpu and machine.gpu
  3. Adjust threadsPerRank if needed
  4. Modify memory allocation

  5. Update Input/Output

  6. Set correct working directory
  7. Update input file names
  8. Specify output locations

  9. Modify Application Commands

  10. Update executable name
  11. Adjust command-line options
  12. Set application-specific parameters

Common Patterns

Multi-node MPI Job

{% set useMpi = ucloud.nodes > 1 %}
{% set executable = ternary(useMpi, "app_mpi", "app") %}
{{ srun() }} {{ executable }}

GPU Job

{% set executable = ternary(ucloud.machine.gpu > 0, "app_gpu", "app") %}
{{ sbatch("gpus-per-task", 1) }}

Hybrid MPI/OpenMP

export OMP_NUM_THREADS={{ threadsPerRank }}
{{ sbatch("cpus-per-task", threadsPerRank) }}

Safety Checks

# Add these to your script
[ -f input.file ] || exit 1              # Check input exists
[ -d "$outputDir" ] || mkdir -p "$outputDir"  # Create output directory
set -e                                    # Exit on error