Moreover I have never tried to use sbatch
before because I thought running a program with srun
should have identical or at least similar performance.
For example, if I were you I would run openmp_101-b.sh
as:
cc -fopenmp -o openmp_101 ./openmp_101.c
export OMP_NUM_THREADS=56 # Anything you want
srun \
--account=courses0101 \
--partition=work \
--nodes=1 \
--ntasks=1 \
--ntasks-per-node=1 \
--cpus-per-task=28 \
--mem=100G \
--time=00:30:00 \
--qos=high \
--mail-type=END,FAIL \
[email protected] \
./openmp_101
This worked well for all of my programs so I have never used sbatch
.
To answer your question I tried to execute your program using sbatch openmp_101-b.sh
and it indeed completed within 15 seconds. However when I used the commands above to execute the program directly using srun
, the program would take more than 140 seconds to complete. In this case, srun
is much slower than sbatch
.
I felt confused and tried to execute my project 1 using sbatch
. And it would take forever to complete the multiplication. However, normally my program would take around two minutes to complete the multiplication. In this case, sbatch
is much slower than srun
.
So now I am also getting confused. I don't know the reason behind this, so hopefully there will be anyone to answer this. However before ending my post I still want to share some fun facts I observed:
If you remove the rand()
call and replace it with something like i*i
, sbatch
will be much slower than srun
. This is funny as my project did not use rand()
, so I guess the performance difference may have something to do with rand()
. Moreover, if you do not use rand()
in your code and use srun
to run your program directly under different thread counts you can notice a difference.
I just don't know why.