Skip to content

Commit f11c44a

Browse files
authored
Merge pull request #63 from MonashDeepNeuron/dev
HPC Training Book v1.3.0 - Parallel Computing challenges rework and other minor fixes
2 parents a7f5515 + f01dd40 commit f11c44a

File tree

2 files changed

+36
-55
lines changed

2 files changed

+36
-55
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# The HPC Training Book
22

3+
![Build Status](https://github.com/MonashDeepNeuron/HPC-Training/workflows/CI/badge.svg)
4+
35
This repository contains the source code for the HPC Training content and challenges for new HPC recruits. This book is available online or can be built locally.
46

57
## Building
68

79
To build this book you need [mdBook](https://rust-lang.github.io/mdBook/index.html) a tool for creating books with Markdown. mdBook can be installed using Cargo - Rust's package manager.
810

911
```sh
10-
$ cargo install mdbook
12+
cargo install mdbook
1113
```
1214

1315
You can build this book you must clone this repository using Git. You can then build it and even serve it to localhost to view in your browser. The serve command will produce a localhost you can view.
1416

1517
```sh
16-
$ git clone https://github.com/MonashDeepNeuron/HPP.git
17-
$ cd HPP
18+
$ git clone https://github.com/MonashDeepNeuron/HPC-Training.git
19+
$ cd HPC-Training
1820

1921
# Build ...
2022
$ mdbook build

src/chapter4/challenges.md

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,51 @@
1-
# Challenges
1+
# Parallel Computing Challenges
22

3-
🚧 Under Construction 🏗️
3+
## Overview
44

5-
## Task 1 - Parallise `for` Loop
5+
- [Parallel Computing Challenges](#parallel-computing-challenges)
6+
- [Overview](#overview)
7+
- [Pre-Tasks](#pre-tasks)
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)
12+
- [Task 5 - Calculate Pi using "Monte Carlo Algorithm"](#task-5---calculate-pi-using-monte-carlo-algorithm)
613

7-
Goal: To to create an array `[0,1,2...100000]`
14+
## Pre-Tasks
815

9-
1. Git clone [HPC-Training-Challenges](https://github.com/MonashDeepNeuron/HPC-Training-Challenges)
10-
2. Go to the directory `challenges/parallel-computing` and open `array.c` file
11-
3. Implement the code to create an array `[0,1,2...100000]` without parallelisation
12-
4. Measure the run time of the code
13-
5. Use `#pragma<>` and potentially other clauses to parallelise the code
14-
6. Compile the code again and check the run time and observe the result
16+
Make sure to clone a copy of **your** challenges repo onto M3, ideally in a personal folder on vf38_scratch.
1517

16-
## Task 2 - Run task 1 on HPC cluster
18+
> Note: 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`.
1719
18-
1. Log into M3
19-
2. Check the available partitions with `show_cluster`
20-
3. Modify `RunHello.sh` to you can run `array.c` on HPC cluster
21-
4. Submit the job to M3
22-
5. Check the slurm output file
20+
## Task 1 - Single Cluster Job using OpenMP
2321

24-
>You can also use [strudel web](https://beta.desktop.cvl.org.au/login) to run the script without sbatch
22+
Create a program in `hello.c` that prints 'Hello, world from thread: <thread-number>' to the output. Launch the job to a node SLURM.
2523

26-
## Task 3 - Reduction Clause
24+
> Note:
25+
>
26+
> - The output of a job is put in a slurm-<job-id>.out file by default.
27+
> - The template slurm job scripts will output the results to a `slurm-<job-name>.out` file.
2728
28-
Goal: To find the sum of the array elements
29+
## Task 2 - Parallel `for` Loop
2930

30-
1. Implement the code in `reduction.c` to find the sum of the array elements without parallelisation
31-
2. Measure the run time of the code
32-
3. Add `#pragma<>` and potentially other clauses to parallelise the code
33-
4. Compile and run `reduction.c` again
34-
5. Check the run time and observe the result
31+
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.
3532

36-
>`module load gcc` to use newer version of gcc if you have error with something like `-std=c99`
33+
> Hint: You will likely need to allocate memory from the heap.
3734
38-
## Task 4 - Private clause
35+
## Task 3 - Parallel Reductions
3936

40-
The goal of this task is to square each value in array and find the sum of them
37+
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?
4138

42-
1. Implement the code in `private.c` to square each value in array and find the sum of them without parallelisation
43-
2. Measure the run time of the code. (You may need to link the math library with `-lm`)
44-
3. Add `#pragma<>` and potentially other clauses to parallelise the code
45-
4. Compile `private.c` again and check the run time and observe the result
39+
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?
4640

47-
## Task 5 - Calculate Pi using "Monte Carlo Algorithm"
48-
49-
Goal: To estimate the value of pi from simulation
50-
51-
1. Implement Monte Carlo in `MonteCarlo.c` without parallelisation
52-
2. Measure the run time of the code
53-
3. Parallelise the code
54-
4. Compile and run `MonteCarlo.c` again
55-
5. Check the run time and observe the result
41+
> Note: `module load gcc` to use newer version of gcc if you have error with something like `-std=c99`.
5642
57-
> You should get a result close to pi(3.1415…….)
43+
## Task 4 - Laplace Equation for Calculating the Temperature of a Square Plane
5844

59-
Short explanation of Monte Carlo algorithm:
45+
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.
6046

61-
[YouTube Video: Monte Carlo Simulation](https://www.youtube.com/watch?v=7ESK5SaP-bc&ab_channel=MarbleScience)
62-
63-
![Monte Carlo](imgs/Monte%20Carlo.png)
64-
65-
## Bonus - Laplace equation to calculate the temperature of a square plane
47+
## Task 5 - Calculate Pi using "Monte Carlo Algorithm"
6648

67-
1. Modify `laplace2d.c` and implement the laplace algorithm
68-
2. Use Makefile to compile the code
69-
3. Make the program as fast as you can
49+
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.
7050

71-
Brief Algorithm of Laplace equation:
72-
![](imgs/Pasted%20image%2020230326142826.png)
51+
[Short explanation of Monte Carlo algorithm](https://www.youtube.com/watch?v=7ESK5SaP-bc&ab_channel=MarbleScience)

0 commit comments

Comments
 (0)