This course is based on: Software Carpentries Intro to HPC and HPC Carpentries HPC Intro to Shell
This course and the contents of this repository are under CC-BY 4.0 license.
AI was used to help in the creation of this course, to structure the lesson, create the scripts and exercises, refine the learning objectives, and prepare the readme files.
You are a new student or intern joining a research project. A collaborator has given you a messy project directory that contains data files, scripts, notes, old job outputs, and temporary files.
Your job is to log in, copy the inherited project into your own workspace, use terminal commands to inspect and organize the files, run a small Python workload, submit it through Slurm, read the job output carefully when something fails, fix the application error, and see a small example of how requesting more CPUs can speed up a parallel workload.
The Python examples are intentionally simple. You do not need to understand machine learning or PyTorch for this session. The Python script is the “payload” for the job.
By the end of this session, you should be able to:
- Use basic terminal commands to navigate and organize files.
- Copy an inherited project into your own workspace.
- Recognize that shared systems have storage limits and quotas.
- Submit a simple batch job using Slurm.
- Use an interactive allocation to test a command.
- Read Slurm output files and distinguish application errors from scheduler messages.
- Recognize that resource requests should match what your code can use.
NERSC Documentation Absolute Beginner's Guide
You should already be able to log in to the NERSC system before this session starts. We will not spend much time troubleshooting accounts, MFA, or SSH setup during the workshop.
cd $CFS/ntrain1
mkdir <myname>
pwdYour instructor will tell you where the shared training files are located. Copy them into your workspace.
mkdir
cp -r /global/cfs/cdirs/ntrain1/RO_HPC_Fundamentals/ <myname>
lsYou should see:
README.md
environment/
example/
instructor/
messy_project/
slurm_scripts/
cd ~/messy_project/
pwd
ls
ls -l
ls results_old
ls temp
find . -maxdepth 3 -type dThis directory represents a common situation: someone has shared a project directory with you, but it is not organized for your new work yet.
This is not about designing the perfect file structure. The goal is to practice terminal basics and get the directory into a usable state.
Your organization may look different from someone else’s. That is okay.
On a shared HPC system, storage is not unlimited. Storage limits are often called quotas. We will cover storage systems and quota policies in more detail in New User Training. For today, just notice that you can check how much space files use.
du -sh .
du -sh *The point for today is simple: organized files are easier to understand, easier to debug, and easier to clean up when you are working on a shared system.
#Stop here - do not go further until instructed
cd ..
ls example/You should see:
01_demo.py
02_demo.py
03_demo.py
cd examples/
cat 01_batch.slurm
sbatch 01_batch.slurm
squeue -u $USERThis job may finish quickly. If it disappears from the queue, that usually means it is no longer running.
Your instructor will provide the exact salloc command for the training system or reservation. A generic example looks like this:
salloc --account=nstaff --constraint cpu --qos shared --nodes 1 --ntasks 1 --cpus-per-task 2 --time=00:20:00Once inside the allocation, try running the first demo directly:
python ../example/01_demo.pyThen try running it through Slurm:
srun python ../example/01_demo.pyFor this simple example, the output may look very similar.
python run.py # runs Python directly where you are
srun python run.py # asks Slurm to launch Python using allocated resources
When you are done with the interactive allocation:
exitls slurm-*.out
less 01_demo-<jobid>.outIn less:
- Spacebar moves down.
bmoves back up./Tracebacksearches for the wordTraceback.qquits.
Look for this pattern:
Training complete.
Traceback (most recent call last):
File "../example/01_demo.py", line 26, in <module>
print(result)
NameError: name 'result' is not defined
You may also see Slurm-related messages after the Python error.
Important lesson:
Slurm launched the job. The Python application crashed.
The actual problem is not “Slurm failed.” The application failed, and Slurm reported that the task exited with an error code.
python ../example/01_demo.pysbatch 01_demo.slurm
squeue -u $USER
ls slurm-*.out
less 01_demo-<jobid>.outOr submit the provided fixed version:
sbatch 02_demo.slurmThis time, the script should finish without the Python traceback.
This short example shows that requesting more CPUs can reduce runtime if the code is written to use those CPUs.
sbatch 04_scale_1_cpu.slurm
sbatch 05_scale_8_cpu.slurm
sbatch 06_scale_32_cpu.slurmWhen they finish, compare the output files:
grep Runtime slurm-scale-*.outExpected pattern:
1 CPU -> slowest
8 CPUs -> faster
32 CPUs -> fastest
The exact times may vary.
Important lesson:
Asking for more resources only helps if your application can use them.
pwd
ls
ls -l
cd directory_name
cd ..mkdir new_directory
mv oldname newname
mv file directory/
cp source destination
cp -r source_directory destination_directory
rmdir empty_directory
rm filenameBe careful with rm -r directory_name: it removes a directory and everything inside it.
cat filename
less filename
head filename
tail filenamedu -sh .
du -sh *sbatch job_script.slurm
squeue -u $USER
srun command
salloc --time=00:05:00 --nodes=1 --ntasks=1 --cpus-per-task=1This session is not about memorizing every command. The goal is to practice a common HPC workflow:
Access the system, understand your files, run your code, read the output, fix errors, and try again.