Getting started with HPC (PBS)
Log in, upload data, write a job script, ask PBS for the right resources and collect the results
This guide takes you from a fresh account to a finished HPC computation. It assumes you already have a MetaCentrum account and can open a terminal. If you do not have an account yet, start with the Account guide.
You will run a small Python script that counts the lines of a text file. The example is trivial on purpose: once it works, you replace the script and the data with your own and keep everything else.
In the code blocks, $ marks a command you type. Lines without it are output. Replace myuser with your username.
New users unfamiliar with grid computing environments often have questions. Please contact user support if you need help - we’re here for you, and your feedback helps us improve the documentation.
Take a look at our latest hands-on tutorials for beginners, which contain lots of useful tips.
How MetaCentrum works
Four terms are enough to follow the rest of this guide.
| Term | What it is | What you do there |
|---|---|---|
| Frontend | A login server, such as tarkil.metacentrum.cz | Prepare files, submit jobs, check results |
| Home directory | Your permanent space on a storage server, such as /storage/praha1/home/myuser | Keep scripts, input data and results |
| Compute node | A powerful machine, you cannot send in the job directly | The scheduler (PBS) runs your job here |
| Scratch | A fast temporary disk on the compute node, available as $SCRATCHDIR | The job works here and cleans up when it ends |

Do not compute on frontends
Frontends are small shared machines. Use them for editing files and submitting jobs only. Anything heavier must run as a job, otherwise it will be stopped. For detailed infrastructure information, see Frontend & Storage guide.
Step 1: Log in
Connect to a frontend with SSH. Any frontend works; pick one near you from the list of frontends.
$ ssh myuser@tarkil.metacentrum.czYou land in your home directory. Create a folder for this tutorial:
$ mkdir first_job
$ cd first_job
$ pwd
/storage/praha1/home/myuser/first_jobWindows users without a terminal can use PuTTY; For the full list of frontends, their locations, and detailed login instructions see the Log in guide.
Step 2: Get your data in
How you transfer data depends on how much of it there is. As a rule of thumb, up to 50 GB and up to 500 files is fine through a frontend. Anything bigger goes directly to the storage server.
Run these commands on your own computer, not on the frontend.
# one file
$ scp myfile.txt myuser@tarkil.metacentrum.cz:~/first_job/
# a whole directory
$ scp -r my_inputs myuser@tarkil.metacentrum.cz:~/first_job/
# a directory, resumable if the connection drops
$ rsync -avh --progress my_inputs myuser@tarkil.metacentrum.cz:~/first_job/For this tutorial, create a small input file directly on the frontend:
$ seq 1 11 > myfile.txtStep 3: Prepare the program
Save the following as counter.py in the first_job folder. You can use the nano editor on the frontend (nano counter.py, then Ctrl+O to save and Ctrl+X to quit) or upload the file the same way as the data.
import sys
infile = sys.argv[1]
outfile = sys.argv[2]
with open(infile, "r", encoding="utf-8") as f:
line_count = sum(1 for _ in f)
with open(outfile, "w", encoding="utf-8") as f:
f.write(str(line_count))Software on MetaCentrum is provided as modules. A module must be loaded before the program can be used, both on the frontend and inside a job.
$ module avail python/ # which versions exist
$ module add python # load the default version
$ module list # what is loaded nowMore about finding software is in the Modules guide.
Module search
You can use wildcards to search: module avail *python*. Add / to see versions within a module directory.
Step 4: Write the job script
A job script is an ordinary shell script with two parts: lines starting with #PBS tell the scheduler what you need, and the rest are the commands to run. Save this as first_job.sh:
#!/bin/bash
# run the job for a max of 30 minutes
#PBS -l walltime=0:30:00
# reserve 1 CPU, 1 GB disc space, 1 GB RAM, and 1 GB scratch space
#PBS -l select=1:ncpus=1:mem=1gb:scratch_local=1gb
# name of the job (not necessary)
#PBS -N my_counter
# stop the script immediately if any command fails,
# so that errors are visible in the error file
set -e
# name a job info file
infofile=job_info.${PBS_JOBID}
# load the python module
module load python
# copy the files to the scratch directory
cp ${PBS_O_WORKDIR}/myfile.txt $SCRATCHDIR
cp ${PBS_O_WORKDIR}/counter.py $SCRATCHDIR
# go to the scratchdir
cd ${SCRATCHDIR}
# create the job info file
touch ${infofile}
# save a basic info about the job
echo -e "Hello world at `date` from user ${USER}!\n" >> ${infofile}
echo -e "$PBS_JOBID is running on node `hostname -f` in a scratch directory $SCRATCHDIR\n" >> ${infofile}
# Run the computation
python counter.py myfile.txt out_count.txt
# copy the outputs back to where qsub was called
cp ${infofile} ${PBS_O_WORKDIR}/
cp out_count.txt ${PBS_O_WORKDIR}/
# apply a scratch automatic cleanup utility
clean_scratchWhat each part does:
#PBS -Nnames the job, so you can recognise it in listings.#PBS -l select=...asks for one machine with 1 CPU, 1 GB of memory and 1 GB of scratch space.#PBS -l walltime=...is the maximum running time, here 10 minutes. The job is stopped when it runs out.$PBS_O_WORKDIRis set by PBS to the directory where you ranqsub.$SCRATCHDIRis set by PBS to your scratch directory on the compute node.clean_scratchis a MetaCentrum utility that empties the scratch. Thetrapline makes sure it runs even when the job fails.
Why copy data to scratch?
Your home directory is a network disk shared by many users. Reading and writing there during the computation is slow for you and for everyone else. Copy inputs to scratch, compute there, and copy only the results back.
Step 5: Submit the job and watch it
Decide whether you want to run your job as a batch job or in interactive mode.
Batch job: Non-interactive: submit the script, and it will run independently (primary choice for grid computing).
Interactive job: Reserve resources, then work interactively (useful for testing, compiling, running GUI apps).
Standard job
Submit the script with qsub. PBS answers with the job ID:
$ qsub first_job.sh
18411451.pbs-m1.metacentrum.czCheck the state of your jobs:
$ qstat -u myuser
Job ID Username Queue Jobname SessID NDS TSK Memory Time S Time
-------------------- -------- -------- ---------- ------ --- --- ------ ----- - -----
18411451.pbs-m1 myuser q_2h first_job -- 1 1 1gb 00:10 Q --The S column shows the state:
| State | Meaning |
|---|---|
Q | Queued, waiting for free resources |
R | Running |
F | Finished (shown only with qstat -x) |
The commands you will need most:
$ qstat -u myuser # my waiting and running jobs
$ qstat -x -u myuser # also jobs finished in the last 24 hours
$ qstat -f 18411451 # everything about one job
$ qdel 18411451 # cancel a jobYou can log out while the job waits or runs. To get an e-mail when it ends, add #PBS -m ae to the script. Your jobs are also listed in the myMetaCentrum portal.
myuser@tarkil:~$ qsub test.sh
> 18411451.pbs-m1.metacentrum.cz
myuser@tarkil:~$ qstat -xu myuser
> Job ID Name User S
----------- ---------- ------ -
18411451... my_counter myuser RWhen the job finishes, you can inspect the standard output and error files in the directory from where the job was submitted.
jobname.o<jobID>– standard output (STDOUT).jobname.e<jobID>– standard error output (STDERR) – check here first if a job fails.
When the job finishes, in your home you can inspect the standard output and error files and the output files, which were created by the job.
myuser@tarkil:~$ ls
> 18411451.pbs-m1.metacentrum.cz counter.py my_counter.o18411451 my_counter.e18411451 out_count.txt test.shmy_counter.o18411451(default file with standard output)my_counter.e18411451(default file with standard error; empty unless the job logged errors)18411451.pbs-m1.metacentrum.cz(output file with job info your batch script has explicitly created)out_count.txt(output file created by the Python script with the number of lines in the input file written to it)
myuser@tarkil:~$ cat out_count.txt
> 11Run as an interactive job
As an alternative, you can run a very similar job interactively.
Request resources for the interactive job:
myuser@tarkil:~$ qsub -I -l walltime=00:30:00 -l select=1:ncpus=1:mem=1gb:scratch_local=1gbWait for the job to start – you will be moved to one of the compute nodes, where you can inspect the new environment.
> qsub: waiting for job 18359645.pbs-m1.metacentrum.cz to start
> qsub: job 18359645.pbs-m1.metacentrum.cz ready
myuser@tarkil16:~$ hostname
> tarkil16.grid.cesnet.cz
myuser@tarkil16:~$ echo $SCRATCHDIR
> /scratch/myuser/job_18359645.pbs-m1
myuser@tarkil16:~$ pwd
> /storage/praha1/home/myuserRun the commands specified in the batch job (load Python module and copy the files to the scratch directory) and enter the scratch directory.
myuser@tarkil16:~$ module load python
myuser@tarkil16:~$ cp ${PBS_O_WORKDIR}/counter.py $SCRATCHDIR
myuser@tarkil16:~$ cp ${PBS_O_WORKDIR}/myfile.txt $SCRATCHDIR
myuser@tarkil16:~$ cd $SCRATCHDIRCall the Python script with the input file and let it count the lines.
myuser@tarkil16:~$ python counter.py myfile.txt out_count.txt
myuser@tarkil16:~$ cat out_count.txt
> 11Copy the output file back to where qsub was run (your home) and clean the scratch.
myuser@tarkil16:~$ cp out_count.txt ${PBS_O_WORKDIR}/
myuser@tarkil16:~$ clean_scratchStep 6: Collect the results
When the job finishes, the first_job folder contains three new files:
$ ls
counter.py first_job.e18411451 first_job.o18411451 first_job.sh myfile.txt out_count.txt
$ cat out_count.txt
11out_count.txtis the result your script copied back.first_job.o18411451holds everything the job printed (standard output).first_job.e18411451holds error messages (standard error). If a job fails, look here first.
To copy results to your computer, run this on your own computer:
$ scp myuser@tarkil.metacentrum.cz:~/first_job/out_count.txt .That is the whole cycle. For your own work, change the module, the input files and the command in the script.
How to ask for resources
Every job declares what it needs. PBS then finds a machine that has it free. Four resources matter for almost every job:
| Resource | Meaning | If you leave it out | Example |
|---|---|---|---|
ncpus | Number of CPU cores | 1 | ncpus=4 |
mem | Memory (RAM) | 400 MB | mem=8gb |
walltime | Maximum running time, hh:mm:ss | 24 hours | walltime=4:00:00 |
scratch_local | Scratch disk space | No guaranteed space | scratch_local=10gb |
They are written on two lines. Resources of the machine go into select, joined by colons; walltime stands alone:
#PBS -l select=1:ncpus=4:mem=8gb:scratch_local=10gb
#PBS -l walltime=4:00:00The number right after select= is the number of machines (chunks). Keep it at 1 unless your program is written to run across several machines with MPI.
Always ask for scratch
Scratch has no default. Without it, $SCRATCHDIR points to a small, slow system directory. Request a size that covers your inputs, temporary files and outputs together.
How much should I ask for?
Ask for a little more than the job needs, not as much as possible.
- Too little: PBS kills a job that exceeds its memory or walltime, and the work is lost.
- Too much: the job waits longer in the queue, because large free slots are rare, and the unused resources are blocked for others. Heavy usage also lowers your priority through fairshare.
A practical way to find the right numbers:
-
Run a small test with a part of your data and generous limits.
-
After it finishes, check what it really used:
$ qstat -xf 18411451 | grep resources_used resources_used.cput = 00:03:12 resources_used.mem = 1843200kb resources_used.ncpus = 1 resources_used.walltime = 00:03:40 -
Request the measured values plus a reserve of about 20 to 30 percent, scaled up for the full data.
Some rules of thumb:
- CPUs: more than 1 helps only if the program can use them (threads, OpenMP, a
--threadsoption). A program that runs on one core gains nothing fromncpus=16. - Memory: if a job dies with a memory error, double the request and try again.
- Walltime: shorter jobs start sooner. If a running job needs more time, you can extend its walltime with
qextend, within limits. - Scratch:
scratch_localsuits most jobs. For jobs with very many small files usescratch_ssd. All types are described in Scratch storages.
Not sure about the syntax? The qsub assembler builds the request from a web form and shows how many machines can satisfy it. The full list of resources is in PBS resources.
Where to go next
- PBS resources: every resource you can request.
- Scratch storages: which scratch type fits your job.
- Parallel computing: OpenMP and MPI across several machines.
- Install your own software: Python packages, R libraries and more.
- OnDemand: files, jobs and graphical applications in a web browser.
- PBS cheatsheet (PDF): the essentials on one page.
- Learn advanced job configuration and troubleshooting
- Explore available software
- Read about parallel computing
- Check GPU resources
- Try usegalaxy.cz web interface – an alternative way to run jobs in a web-based platform with workflow support.
- Account lifecycle - accounts expire February 2nd. You’ll be notified by email, ask for its renewal regularly.
- Use a strong password and never share credentials. For password changes and complete security rules, see Account page and Terms and conditions.
Troubleshooting basics
If your job fails:
- Check the error file (
*.e<jobID>). - Verify your input files exist and have the correct permissions.
- Check if software modules are loaded correctly.
- Ensure you requested adequate resources (memory, walltime, scratch).
The most common problems:
| Symptom | Likely cause | What to do |
|---|---|---|
The job waits in Q for a long time | The request is large or very specific | Lower ncpus, mem or walltime; check the request in the qsub assembler |
| The job ended early and the results are missing | Walltime ran out | Request more time, or extend a running job with qextend |
Error mentions memory or Cgroup memsw limit exceeded | The job used more memory than requested | Request more mem; see the FAQ entry |
No space left on device | Scratch or quota is full | Request more scratch; see the FAQ entry |
command not found | The module is not loaded inside the job | Add module add ... to the script |
qsub says script contains cr, lf | The script was edited on Windows | Convert the line endings; see the FAQ entry |
qdel does not remove the job | The job is stuck | Use qdel -W force; see the FAQ entry |
If the job failed and left data in scratch, you can inspect it from the frontend with go_to_scratch <jobID> within 24 hours.
For jobs older than a day, pbs-get-job-history <jobID> retrieves the script and its output; see Finished jobs.
For more advanced troubleshooting, see the Advanced guide.
Still stuck? Write to user support. Include your username, the job ID and the error message.
Acknowledgements
Publications created with MetaCentrum support must be submitted to the publications system and acknowledged.
See Terms and conditions for an up-to-date acknowledgement wording.
Examples
Each example shows only what differs from the script in Step 4. The copy-in, compute, copy-out pattern stays the same.
Example 1: Multi-threaded program
For software that can use several cores on one machine. Tell the program how many cores it may use; otherwise it may try to use all cores of the machine and the job will be killed.
#!/bin/bash
#PBS -N threads
#PBS -l select=1:ncpus=8:mem=16gb:scratch_local=20gb
#PBS -l walltime=4:00:00
trap 'clean_scratch' EXIT TERM
export OMP_NUM_THREADS=$PBS_NUM_PPN # 8, taken from the request
cp $PBS_O_WORKDIR/input.dat $SCRATCHDIR/
cd $SCRATCHDIR
module add my_software
my_program --threads $PBS_NUM_PPN input.dat > output.dat
cp output.dat $PBS_O_WORKDIR/Example 2: Large memory, long run
Nothing changes except the numbers. Add an e-mail notification so you do not need to keep checking.
#PBS -l select=1:ncpus=4:mem=120gb:scratch_local=200gb
#PBS -l walltime=72:00:00
#PBS -m aeExample 3: GPU job
Add ngpus. PBS routes the job to a GPU queue by itself. If the model needs a certain amount of GPU memory, request it with gpu_mem.
#!/bin/bash
#PBS -N gpu_test
#PBS -l select=1:ncpus=4:ngpus=1:gpu_mem=16gb:mem=32gb:scratch_local=50gb
#PBS -l walltime=8:00:00
trap 'clean_scratch' EXIT TERM
cp -r $PBS_O_WORKDIR/project $SCRATCHDIR/
cd $SCRATCHDIR/project
nvidia-smi # prints which GPU the job received
python train.py
cp -r results $PBS_O_WORKDIR/See GPU jobs for all GPU options.
Example 4: Many similar jobs (job array)
To process 100 input files with the same script, submit one job array instead of 100 separate jobs. Each sub-job receives its own number in $PBS_ARRAY_INDEX.
#!/bin/bash
#PBS -N array
#PBS -l select=1:ncpus=1:mem=2gb:scratch_local=5gb
#PBS -l walltime=1:00:00
#PBS -J 1-100
trap 'clean_scratch' EXIT TERM
INPUT=sample_${PBS_ARRAY_INDEX}.txt
cp $PBS_O_WORKDIR/counter.py $PBS_O_WORKDIR/inputs/$INPUT $SCRATCHDIR/
cd $SCRATCHDIR
module add python
python counter.py $INPUT count_${PBS_ARRAY_INDEX}.txt
cp count_${PBS_ARRAY_INDEX}.txt $PBS_O_WORKDIR/results/The resources are requested per sub-job, not for the whole array. Create the results folder before you submit. More in Job arrays.
Example 5: Interactive job
An interactive job gives you a command line on a compute node. Use it to test commands before writing a script, to compile software or to download large data.
$ qsub -I -l select=1:ncpus=2:mem=4gb:scratch_local=10gb -l walltime=2:00:00
qsub: waiting for job 18359645.pbs-m1.metacentrum.cz to start
qsub: job 18359645.pbs-m1.metacentrum.cz ready
$ cd $SCRATCHDIR
$ module add python
$ python # work as you would on your own computerWhen you are done, copy the results home, clean up and leave:
$ cp results.txt $PBS_O_WORKDIR/
$ clean_scratch
$ exitThe job ends when you type exit, when the walltime runs out, or when the connection to the frontend is lost.
Last updated on
