Skip to content
Snippets Groups Projects
Commit 7a881136 authored by Mactavish's avatar Mactavish
Browse files

update slides

parent f63894f5
No related branches found
No related tags found
No related merge requests found
# ALP4 Tutorial-5 # ALP4 Tutorial-6
This branch contains all materials for the 5th tutorial session. This branch contains all materials for the 6th tutorial session.
## Agenda ## Agenda
- Assignment's solution presentation (if any) - Assignment's solution presentation (if any)
- Recap & Discussion: Deadlocks, Semaphores, Monitor - Recap & Discussion: Parallelism, OpenMP
- Q&A - Q&A
...@@ -6,7 +6,7 @@ title: Q&A ...@@ -6,7 +6,7 @@ title: Q&A
Any questions about: Any questions about:
- Third Assignment Sheet
- Fourth Assignment Sheet - Fourth Assignment Sheet
- Fifth Assignment Sheet
- Topics from the lectures - Topics from the lectures
- Organisation - Organisation
--- ---
title: Recap I title: Recap I
layout: center
--- ---
# Recap & Discussion # Recap & Discussion
### Resources ### Parallel Programming
- What are resources? What kinds of resources are there?
- How are these resources managed? Who is managing the resources?
- When do we need to manage the resources?
- What are the potential issues in the context of resource management?
<br/>
<v-click>
### Possible Answers
- Hardware (physical), or any piece of information (virtual). - Concurrency vs Parallelism
- limited/unlimited - Concurrent programming vs parallel programming
- preemptable/nonpreemptable - Programming with shared memory vs message passing
- Allocation/acquisition <-> Deallocation/release, by programmers or by the OS
- When resources are limited
- Priories, Performance, Fairness, Deadlocks
</v-click>
--- ---
title: Recap II title: Recap II
layout: center
--- ---
### Deadlocks # How to Design Parallel Programs/Applications?
- What are deadlocks?
- What are the conditions for resource deadlocks?
- How do we handle deadlocks? What are the differences between those approaches?
<br/>
<v-click> <v-click>
### Possible Answers Using Foster's Design Methodology.
- Permanent blocking of a set of processes that compete for system resources
- Conditions for deadlocks (1-3: Possibility, 1-4: Existence)
- 1. Mutual exclusion on resources
- 2. Hold-and-wait
- 3. No preemption
- 4. Circular wait
- Prevention, Avoidance, Detection, Resolution (Differences as the names suggest)
</v-click> </v-click>
---
title: Recap III
---
### Deadlock Avoidance - The Banker's Algorithm
**Idee**: Do not grant a resource request if this allocation might lead to deadlock (unsafe situation).
### Exercises
There are 5 threads and 4 types of resources in the system. $G$ represents the total requests for resources. $B$ represents the current allocation of resources. $v$ represents the total amount of resource in the system.
$$
G = \begin{pmatrix}
2 & 1 & 0 & 0 \\
5 & 4 & 2 & 1 \\
6 & 6 & 3 & 4 \\
5 & 3 & 1 & 3 \\
5 & 6 & 2 & 3
\end{pmatrix}
B = \begin{pmatrix}
2 & 0 & 0 & 0 \\
3 & 3 & 2 & 1 \\
1 & 1 & 1 & 1 \\
1 & 0 & 0 & 1 \\
1 & 2 & 0 & 2
\end{pmatrix}
v = \begin{pmatrix} 9 & 6 & 3 & 5 \end{pmatrix}
$$
- Use the Banker's algorithm to decide if the situation is safe. Write down every intermediate steps.
- Change the vector $v$ in such way that a safe situation becomes unsafe, vice versa. Write down every intermediate steps as well.
---
title: Recap III
layout: center
---
# Discussion: Restrictions of Deadlock Avoidance
<br/>
<v-clicks> <v-clicks>
- Knowledge about number of threads and their maximum resource requirements in advance - **Partitioning**: The process of dividing the computation and data into pieces.
- Fixed number of resources - **Communication**: The process of determining how tasks will communicate with each other, distinguishing between local communication and global communication.
- No process may exit while holding resources. - **Agglomeration**: The process of grouping tasks into larger tasks to improve performance or simplify programming.
- Not applicable to dynamic systems - **Mapping**: The process of assigning tasks to physical processor.
</v-clicks> </v-clicks>
--- ---
title: Recap IV title: Recap III
layout: center
--- ---
# Dining Philosophers Problem # OpenMP
What are the potential issues here if we want to solve this problem? An API for Writing Multithreaded Applications.
<v-clicks> - A set of compiler directives and library routines
- Greatly simplifies writing multi-threaded programs in C/C++, Fortran
- Deadlock - Standardized
- Fairness
- Performance
</v-clicks>
---
title: Recap V
layout: center
---
# Discussion: Mutex, Semaphore and Monitor <br/>
- What are the differences? ### Assumptions
- What do they have in common?
--- GNU GCC or Clang is already available on your machine.
title: Recap V
layout: center
---
# Programming Exercises Details about OpenMP support in compilers can be found with the following links:
1. Fix the deadlock bug in `exercises/deadlock` - [GNU](https://gcc.gnu.org/projects/gomp/)
2. Implement semaphore using conditional variables in `exercises/semaphore` - [Clang](https://clang.llvm.org/docs/OpenMPSupport.html)
You can also take a look at [OpenMP reference cards](https://www.openmp.org/resources/refguides/).
...@@ -16,7 +16,7 @@ transition: fade-out ...@@ -16,7 +16,7 @@ transition: fade-out
css: unocss css: unocss
--- ---
# ALP4 Tutorial 5 # ALP4 Tutorial 6
## Chao Zhan ## Chao Zhan
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment