Compiling and executing a parallel OpenMP Fortran program
Let’s compile and execute the program ProgPAR_OpenMP.f90.
Definition of the compiling environment:
Supposing that we want to use Cascade partition, we have to connect to one of the login nodes for this partition, for example s92node01 (see Login nodes).
To use the software modules for this partition, we have to execute:
module use /applis/PSMN/debian11/Cascade/modules/all
Now we can see available modules:
module avail
Load a module for GNU compilers (GCC):
module load GCC/10.3.0
export OMP_NUM_THREADS=16
We can check the compiler version:
gfortran --version
GNU Fortran (GCC) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
Compilation
gfortran -fopenmp -o ProgPAR_OpenMP.f90.exe ProgPAR_OpenMP.f90
The binary file (executable) SommeVecVecSEQ.f90.exe has been generated.
Note
If you prefer to use the Intel compiler, then you have to load the intel/2021a module (instead of GCC/10.3.0) and launch the compilation with the ifort command (instead of gfortran)
Interactive execution (on login node):
./ProgPAR_OpenMP.f90.exe
The result is displayed on the screen :
Hello World from thread = 0
Number of threads = 16
Hello World from thread = 5
Hello World from thread = 4
Hello World from thread = 15
Hello World from thread = 10
Hello World from thread = 13
Hello World from thread = 2
Hello World from thread = 11
Hello World from thread = 12
Hello World from thread = 3
Hello World from thread = 1
Hello World from thread = 14
Hello World from thread = 6
Hello World from thread = 9
Hello World from thread = 7
Hello World from thread = 8
Batch execution (by submitting to Cascade partition):
We use a submission script.sh (for parallel OpenMP program) to submit a job which will run the program on compute nodes.
This submission script configures the environment and then run the binary (with its options, if any) on the compute node.
sbatch script.sh
Submitted batch job 649
The job is waiting that asked ressources become availables and then it will be in Running state:
squeue
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
649 Cascade Par_Open mylogin R 0:00 1 s92node02
As prescribed in submission script, the standard output is redirected to the file Par_OpenMP.649.s92node02.out and the standard error is redirected to the file Par_OpenMP.649.s92node02.err.
-rw-r--r-- 1 mylogin cbp 0 25 janv. 09:21 Par_OpenMP.649.s92node02.err
-rw-r--r-- 1 mylogin cbp 419 25 janv. 09:21 Par_OpenMP.649.s92node02.out
When the job is finished, we can see the output file as following:
cat Par_OpenMP.649.s92node02.out
Hello World from thread = 0
Hello World from thread = 9
Hello World from thread = 12
Hello World from thread = 11
Hello World from thread = 13
Hello World from thread = 10
Hello World from thread = 14
Hello World from thread = 4
Hello World from thread = 3
Hello World from thread = 5
Hello World from thread = 6
Hello World from thread = 7
Hello World from thread = 8
Hello World from thread = 1
Hello World from thread = 2
Number of threads = 16
Hello World from thread = 15