Skip to content

Commit

Permalink
Updated OpenMP examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pkrastev committed Apr 22, 2024
1 parent 390f292 commit 28c9726
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Parallel_Computing/EP/Example2/run.sbatch
@@ -1,6 +1,6 @@
#!/bin/bash
#SBATCH -J test_job
#SBATCH -p testg
#SBATCH -p test
#SBATCH -c 1
#SBATCH -t 00:20:00
#SBATCH --mem=4G
Expand Down
6 changes: 3 additions & 3 deletions Parallel_Computing/OpenMP/Example1/Makefile
@@ -1,13 +1,13 @@
#=================================================
# Makefile
#=================================================
CFLAGS = -c -O2 -qopenmp
COMPILER = icx
CFLAGS = -c -O2 -fopenmp
COMPILER = gcc
PRO = omp_hello
OBJECTS = ${PRO}.o

${PRO}.x : $(OBJECTS)
$(COMPILER) -o ${PRO}.x $(OBJECTS) -qopenmp
$(COMPILER) -o ${PRO}.x $(OBJECTS) -fopenmp

%.o : %.c
$(COMPILER) $(CFLAGS) $(<F)
Expand Down
8 changes: 4 additions & 4 deletions Parallel_Computing/OpenMP/Example1/README.md
Expand Up @@ -9,14 +9,14 @@ The master thread only prints the total number of threads.
* <code>omp_hello.c</code>: C source code
* <code>omp_hello.dat</code>: Output file
* <code>Makefile</code>: Makefile to compile the code
* <code>sbatch.run</code>: Batch-job submission script
* <code>run.sbatch</code>: Batch-job submission script

### Example Usage:

```bash
module intel/23.2.0-fasrc01 # Load required software modules
module gcc/13.2.0-fasrc01 # Load required software modules
make # Compile
sbatch sbatch.run # Send the job to the queue
sbatch run.sbatch # Send the job to the queue
```

### Source Code:
Expand Down Expand Up @@ -70,7 +70,7 @@ int main (int argc, char *argv[]) {
PRO=omp_hello
# Load required software modules
module load intel/23.2.0-fasrc01
module load gcc/13.2.0-fasrc01
# Run program
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
Expand Down
4 changes: 2 additions & 2 deletions Parallel_Computing/OpenMP/Example1/omp_hello.dat
@@ -1,5 +1,5 @@
Hello World from thread = 0
Hello World from thread = 2
Number of threads = 4
Hello World from thread = 1
Hello World from thread = 2
Hello World from thread = 3
Number of threads = 4
Expand Up @@ -12,7 +12,7 @@
PRO=omp_hello

# Load required software modules
module load intel/23.2.0-fasrc01
module load gcc/13.2.0-fasrc01

# Run program
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
Expand Down
4 changes: 2 additions & 2 deletions Parallel_Computing/OpenMP/Example2/README.md
Expand Up @@ -96,8 +96,8 @@ end program omp_diag
### Example Usage:

```bash
module load intel/23.2.0-fasrc01
module load intel-mkl/23.2.0-fasrc01
module load intel/24.0.1-fasrc01
module load intel-mkl/24.0.1-fasrc01
make
sbatch run.sbatch
```
Expand Down
20 changes: 10 additions & 10 deletions Parallel_Computing/OpenMP/Example2/omp_diag.out
@@ -1,12 +1,12 @@
Number of threads: 4
First M eigen values of h:
1 -18.1848684427201
2 -18.1550827572934
3 -18.0007070579734
4 -17.6948506483233
5 -17.5459913484698
6 -17.3478385203436
7 -17.3089301917710
8 -17.1912406136957
9 -17.0931549184341
10 -17.0653170991318
1 -18.0954645905172
2 -18.0188076962175
3 -17.8616966140614
4 -17.7059379575756
5 -17.5260581737241
6 -17.3683102523537
7 -17.3166945069298
8 -17.1806538457236
9 -17.1063185383464
10 -17.0355580705925
6 changes: 3 additions & 3 deletions Parallel_Computing/OpenMP/Example2/run.sbatch
Expand Up @@ -2,15 +2,15 @@
#SBATCH -J omp_diag
#SBATCH -o omp_diag.out
#SBATCH -e omp_diag.err
#SBATCH -p test
#SBATCH -p rc-testing
#SBATCH -t 30
#SBATCH -N 1
#SBATCH -c 4
#SBATCH --mem=4G

# Set up environment
module load intel/23.2.0-fasrc01
module load intel-mkl/23.2.0-fasrc01
module load intel/24.0.1-fasrc01
module load intel-mkl/24.0.1-fasrc01

# Run program
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
Expand Down
10 changes: 5 additions & 5 deletions Parallel_Computing/OpenMP/Example3/README.md
Expand Up @@ -7,14 +7,14 @@
* <code>omp_pi.c</code>: C source code
* <code>omp_pi.dat</code>: Output file
* <code>Makefile</code>: Makefile to compile the code
* <code>sbatch.run</code>: Batch-job submission script
* <code>run.sbatch</code>: Batch-job submission script
* <code>speedup.py</code>: Python code to generate speedup figure
* <code>speedup.png</code>: Speedup figure

### Example Usage:

```bash
module load intel/23.2.0-fasrc01 # Load required software modules
module load intel/24.0.1-fasrc01 # Load required software modules
make # Compile
sbatch sbatch.run # Send the job to the queue
```
Expand Down Expand Up @@ -116,7 +116,7 @@ rm -rf ${PRO}.dat speedup.png
touch ${PRO}.dat

# --- Load required software modules ---
module load intel/23.2.0-fasrc01
module load intel/24.0.1-fasrc01
unset OMP_NUM_THREADS
# --- Run program with 1, 2, 4, and 8 OpenMP threads ---
for i in 1 2 4 8
Expand All @@ -131,7 +131,7 @@ cat omp_pi.dat | grep -e Time -e Number | awk -F ":" '{if ($1 ~ "Time" ) {prin

# --- Generate speedup figure ---
sleep 2
module load python/3.10.12-fasrc01
module load python/3.10.13-fasrc01
source activate python-3.10_env
python speedup.py
```
Expand All @@ -141,7 +141,7 @@ python speedup.py
## Example conda env:

```bash
module load python/3.10.12-fasrc01
module load python/3.10.13-fasrc01
mamba create -n python-3.10_env python=3.10 pip wheel numpy scipy matplotlib pandas seaborn h5py
```
### Example Output:
Expand Down
4 changes: 2 additions & 2 deletions Parallel_Computing/OpenMP/Example3/omp_pi.dat
@@ -1,12 +1,12 @@
Number of threads: 1
Exact value of PI: 3.14159
Estimate of PI: 3.14154
Time: 2.56 sec.
Time: 2.54 sec.

Number of threads: 2
Exact value of PI: 3.14159
Estimate of PI: 3.14151
Time: 1.28 sec.
Time: 1.27 sec.

Number of threads: 4
Exact value of PI: 3.14159
Expand Down
13 changes: 13 additions & 0 deletions Parallel_Computing/OpenMP/Example3/omp_pi.out
@@ -0,0 +1,13 @@
Number of threads: 1

Number of threads: 2

Number of threads: 4

Number of threads: 8

Nthreads Walltime Speedup Efficiency (%)
1 2.54 1.00 100.00
2 1.27 2.00 100.00
4 0.64 3.97 99.22
8 0.32 7.94 99.22
Expand Up @@ -3,17 +3,17 @@
#SBATCH -o omp_pi.out
#SBATCH -e omp_pi.err
#SBATCH -t 0-00:30
#SBATCH -p test
#SBATCH -p rc-testing
#SBATCH -N 1
#SBATCH -c 8
#SBATCH --mem=4000
#SBATCH --mem=4G

PRO=omp_pi
rm -rf ${PRO}.dat speedup.png
touch ${PRO}.dat

# --- Load required software modules ---
module load intel/23.2.0-fasrc01
module load intel/24.0.1-fasrc01
unset OMP_NUM_THREADS
# --- Run program with 1, 2, 4, and 8 OpenMP threads ---
for i in 1 2 4 8
Expand All @@ -28,6 +28,6 @@ cat omp_pi.dat | grep -e Time -e Number | awk -F ":" '{if ($1 ~ "Time" ) {prin

# --- Generate speedup figure ---
sleep 2
module load python/3.10.12-fasrc01
module load python/3.10.13-fasrc01
source activate /n/home06/pkrastev/holystore01/conda/python-3.10_env
python speedup.py
4 changes: 2 additions & 2 deletions Parallel_Computing/OpenMP/Example3/scaling_results.txt
@@ -1,4 +1,4 @@
1 2.56
2 1.28
1 2.54
2 1.27
4 0.64
8 0.32
Binary file modified Parallel_Computing/OpenMP/Example3/speedup.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions Parallel_Computing/OpenMP/Example3/tmp/scaling_results.txt

This file was deleted.

Binary file removed Parallel_Computing/OpenMP/Example3/tmp/speedup.png
Binary file not shown.
44 changes: 0 additions & 44 deletions Parallel_Computing/OpenMP/Example3/tmp/speedup.py

This file was deleted.

0 comments on commit 28c9726

Please sign in to comment.