How to Edit HPC Job Scripts¶
Quick Start¶
- 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¶
- Backup Your Script
cp job.sh job.sh.backup
- Check Resource Settings
- Review
machine.cpu
andmachine.gpu
- Adjust
threadsPerRank
if needed -
Modify memory allocation
-
Update Input/Output
- Set correct working directory
- Update input file names
-
Specify output locations
-
Modify Application Commands
- Update executable name
- Adjust command-line options
- 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