-
--nodes, --ntasks,
--ntasks-per-node, and --cpus-per-task are the
node, the ranks, the ranks per node, and the cores (threads) per
rank.
-
sbatch reserves resources. srun starts the
tasks.
-
module load 2025 and
module load foss/2025a belong in the job.
mpicc -v shows the compiler the job loaded.
- Eight tasks with four per node print four hostname lines for each of
two hosts.
- The course-cluster hostname override is
--nodes=3 --ntasks=6 --ntasks-per-node=2.
- AXPY is pointwise. The hybrid code has no reduction. Bandwidth
limits it, so speedup flattens early.
- Sequential compile and run:
gcc -O2 axpy.c -o axpy.out
and srun ./axpy.out $N.
- Hybrid compile and run:
mpicc -O2 -fopenmp axpy-hybrid.c -o axpy-hybrid.out,
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK, and
srun ./axpy-hybrid.out $N.
-
y[0] is 202 for this initialisation and 100
repetitions. The local length is the global length split across
tasks.
- Two-core submissions:
sbatch --cpus-per-task=1 submit-axpy.sh 10000000 and
sbatch --ntasks=2 submit-axpy-hybrid.sh 10000000.
- The products are independent. The sum is a reduction.
- OpenMP uses
reduction(+:local_sum). MPI uses
MPI_Allreduce with MPI_SUM, the all-ranks form
of MPI_Reduce.
- Compile and run with
mpicc -O2 -fopenmp dot-hybrid.c -o dot-hybrid.out -lm,
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK, and
srun ./dot-hybrid.out $N.
- The printed result matches the sequential digits. Later digits can
differ because the add order differs.
- The course command is
sbatch --nodes=3 --ntasks=6 submit-dot-hybrid.sh 30000000.
-
C[i][j] is 2 * n for these inputs, and
Matrix checksum: is 2 n^3.
- The same
n prints the same checksum. The printf format
is %.17g.
- The sequential compile and run lines are
gcc -O2 matmul.c -o matmul.out and
srun ./matmul.out $N.
- The course size-500 line is
sbatch --cpus-per-task=1 submit-matmul.sh 500.
- Parallelise the outer
i loop with
#pragma omp parallel for, compile with
-fopenmp, and leave the checksum unchanged.