Skip to content

Commit b5c5c13

Browse files
committed
Updated the parallel computing challenges
1 parent 12bac7b commit b5c5c13

32 files changed

+456
-184
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ dkms.conf
5555
*
5656
!/**/
5757
!*.*
58+
59+
# Makefiles
60+
!Makefile

.vscode/settings.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
"files.associations": {
33
"*.tpl": "cpp",
44
"*.bazel": "starlark",
5-
"print.h": "c"
5+
"*.rddl": "txt",
6+
"*.slurm": "shellscript",
7+
"print.h": "c",
8+
"array": "c",
9+
"deque": "c",
10+
"string": "c",
11+
"unordered_map": "c",
12+
"vector": "c",
13+
"string_view": "c",
14+
"initializer_list": "c",
15+
"stdlib.h": "c",
16+
"laplace2d-parallel.h": "c",
17+
"math.h": "c"
618
}
719
}

challenges/parallel-computing/Makefile

Lines changed: 0 additions & 12 deletions
This file was deleted.

challenges/parallel-computing/MonteCarlo.c

Lines changed: 0 additions & 14 deletions
This file was deleted.

challenges/parallel-computing/README.md

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,46 @@
44

55
- [Parallel Computing Challenges](#parallel-computing-challenges)
66
- [Overview](#overview)
7-
- [Task 1 - Parallise `for` Loop](#task-1---parallise-for-loop)
8-
- [Task 2 - Run task 1 on HPC cluster](#task-2---run-task-1-on-hpc-cluster)
9-
- [Task 3 - Reduction Clause](#task-3---reduction-clause)
10-
- [Task 4 - Private clause](#task-4---private-clause)
7+
- [Notice](#notice)
8+
- [Task 1 - Single Cluster Job using OpenMP](#task-1---single-cluster-job-using-openmp)
9+
- [Task 2 - Parallel `for` Loop](#task-2---parallel-for-loop)
10+
- [Task 3 - Parallel Reductions](#task-3---parallel-reductions)
11+
- [Task 4 - Laplace Equation for Calculating the Temperature of a Square Plane](#task-4---laplace-equation-for-calculating-the-temperature-of-a-square-plane)
1112
- [Task 5 - Calculate Pi using "Monte Carlo Algorithm"](#task-5---calculate-pi-using-monte-carlo-algorithm)
12-
- [Bonus - Laplace equation to calculate the temperature of a square plane](#bonus---laplace-equation-to-calculate-the-temperature-of-a-square-plane)
1313

14-
## Task 1 - Parallise `for` Loop
14+
## Notice
1515

16-
Goal: To to create an array `[0,1,2………...19]`
16+
For every challenge you will be running the programs as SLURM jobs. This is so we don't overload the login nodes. A template [SLURM job script](./job.slurm) is provided at the root of this directory which you can use to submit your own jobs to SLURM by copying it to each challenges sub-directory and filling in the missing details. You may need more than one for some challenges. This template will put the would-be-printed output in a file named `slurm-<job-name>.out`.
1717

18-
1. Compile array.c and execute it. Check the run time of the serial code
19-
2. Add `#pragma<>`
20-
3. Compile the code again
21-
4. Run parallel code and check the improved run time
18+
## Task 1 - Single Cluster Job using OpenMP
2219

23-
## Task 2 - Run task 1 on HPC cluster
20+
Create a program in `hello.c` that prints 'Hello, world from thread: <thread-number>' to the output. Launch the job to a node SLURM.
2421

25-
1. Check the available partitions with `show_cluster`
26-
2. Modify `RunHello.sh`
27-
3. `sbatch RunHello.sh`
28-
4. `cat slurm<>.out` and check the run time
22+
> Note:
23+
>
24+
> - The output of a job is put in a slurm-<job-id>.out file by default.
25+
> - The template slurm job scripts will output the results to a `slurm-<job-name>.out` file.
2926
30-
> You can also use [strudel web](https://beta.desktop.cvl.org.au/login) to run the script without sbatch.
27+
## Task 2 - Parallel `for` Loop
3128

32-
## Task 3 - Reduction Clause
29+
In `array-gen.c` implement a program that generates an array containing the numbers 0..10'000 elements (inclusive) using a `for` loop. Measure the execution time using the `time` Linux command. Now reimplement the program to utilise OpenMP's parallel `for` loop macros, measuring the execution time again. Is there any performance improvement? Are the elements still in the correct order and if not how can you fix this. Try experimenting with different sized arrays and element types.
3330

34-
Goal: To find the sum of the array elements
31+
> Hint: You will likely need to allocate memory from the heap.
3532
36-
1. Compile `reduction.c` and execute it. Check the run time
37-
2. Add `#pragma<>`
38-
3. Compile `reduction.c` again
39-
4. Run parallel code and check the improved run time. Make sure you got the same result as the serial code
33+
## Task 3 - Parallel Reductions
4034

41-
> `module load gcc` to use newer version of gcc if you have error with something like `-std=c99`
35+
In the C chapter we created a sum program that summed the elements of an array together. Using this as a base, create a new program that again computes the sum of the elements of an array but using OpenMP, comparing the execution time between the sequential and parallel versions. Is there any performance improvement? How would using a different binary operator change our ability to parallelize the the reduction?
4236

43-
## Task 4 - Private clause
37+
If you have time, implement the sum but at each iteration, raise the current value to the power of the current accumulation divide by 100, adding this to the accumulation. Test a serial and parallel version. Is the parallel any faster?
4438

45-
The goal of this task is to square each value in array and find the sum of them
39+
> Note: `module load gcc` to use newer version of gcc if you have error with something like `-std=c99`.
4640
47-
1. Compile private.c and execute it. Check the run time. `#include` the default library `<math.h>` and link it
48-
2. Add `#pragma<>`
49-
3. Compile `private.c` again
50-
4. Run parallel code and check the improved run time
41+
## Task 4 - Laplace Equation for Calculating the Temperature of a Square Plane
5142

52-
## Task 5 - Calculate Pi using "Monte Carlo Algorithm"
53-
54-
Goal: To estimate the value of pi from simulation
55-
56-
- No instructions on this task. Use what you have learnt in previous tasks to run a parallel code!
57-
- You should get a result close to pi(3.1415…….)
43+
For this challenge you will attempt to parallelize an existing implementation of the Laplace Equation. Throughout the source files of this project there are various loops you can try and make faster by utilizing OpenMP macros. See if you can make a faster version in the `laplace2d-parallel.c`. To build these files make sure you're in that directory and use the command `make`. The executables will be in the same directory.
5844

59-
Short explanation of Monte Carlo algorithm:
60-
61-
[https://www.youtube.com/watch?v=7ESK5SaP-bc&ab_channel=MarbleScience](https://www.youtube.com/watch?v=7ESK5SaP-bc&ab_channel=MarbleScience)
62-
63-
## Bonus - Laplace equation to calculate the temperature of a square plane
45+
## Task 5 - Calculate Pi using "Monte Carlo Algorithm"
6446

65-
- Modify `laplace2d.c`
66-
- Use Makefile to compile the code
67-
- Make the program as fast as you can
47+
For this challenge you will have to try and implement the Monte Carlo algorithm with no framework or template and using everything you've learnt so far. Good luck.
6848

69-
Brief Algorithm of Laplace equation:
49+
[Short explanation of Monte Carlo algorithm](https://www.youtube.com/watch?v=7ESK5SaP-bc&ab_channel=MarbleScience)

challenges/parallel-computing/array.c

Lines changed: 0 additions & 15 deletions
This file was deleted.

challenges/parallel-computing/hello.c

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
#SBATCH --job-name=
4+
#SBATCH --time=0:05:00
5+
#SBATCH --ntasks=1
6+
#SBATCH --cpus-per-task=1
7+
#SBATCH --partition=
8+
#SBATCH --output=slurm-%x.out
9+
#SBATCH --error=slurm-%x.err
10+
11+
# Job commands here
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
CC := gcc
3+
FLAGS := -fopenmp
4+
5+
laplace_sequential: jacobi.c laplace2d.c
6+
${CC} -o laplace-sequential jacobi.c laplace2d.c -lm
7+
8+
laplace_parallel: jacobi.c laplace2d-parallel.c
9+
${CC} ${FLAGS} -o laplace-parallel jacobi-parallel.c laplace2d-parallel.c -lm
10+
11+
clean:
12+
rm laplace-sequential rm laplace-parallel
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Challenge 4 - Laplace Algorithm
2+
3+
## Expected Output
4+
5+
```sh
6+
Jacobi relaxation Calculation: 2000 x 2000 mesh
7+
0, 25.000000
8+
100, 0.239706
9+
200, 0.120432
10+
300, 0.080371
11+
400, 0.060346
12+
Total runtime: <runtime> s
13+
```

0 commit comments

Comments
 (0)