L14 & L15 Flashcards

1
Q

What are 2 advantages of std::thread over pthreads?

A

Type checking is possible

less repetitive code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does the std lock, lock_guard, act?

A

locks at creating and unlocks at destruction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is parallel STL? What is an advantage of it?

A

Parallel STL provides high level parallelism through the C++ standard library. It provides parallelized algorithms for performing computations concurrently on multi-core processors.

It can help prevent data races

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 4 execution policies in Parallel STL?

A

 Sequenced_policy
 Unsequenced_policy (SIMD)
 Parallel_policy
 Parallel_unsequenced_policy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how are Parallel STL algorithms related to functional programming

A

STL algorithms are compositional, meaning composable transformations can be made on data, rather than sequences of instructions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain std::future from the C standard library.

A

Used for accessing results of asynchronous operations through shared memory

Allows offload computation (std::async, std::packaged_task, std::promise)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What 3 level abstractions offer an alternative to high level and low level standard parallelism, outlining an advantage of each?

A

Parallel libraries: low effort from programmer:

Domain specific languages: easier to program, optimise and parallelise (ex: Matlab, Tensorflow

Algorithmic skeletons: focusses on how the computation flows not what it does, utilising composability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is OpenMP an algorithmic skeleton?

A

No, because it is not particularly composable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some disadvantages of algorithmic skeletons?

A

Some parallelism is not structured

Synchronisation automated but still an overhead

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the main goal for OpenMP?

A

Parallel performance for serial code with minimal effort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is used to start a parallel region in OpenMP?

A

pragma omp parallel

  • # pragma: tells the compiler this is a directive
  • omp: pass the directive to the OpenMP system
  • parallel: block that follows is a parallel region
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is reduction used for in a parallel for loop?

A

Reduction can be used to combine each thread’s results in a for loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In OpenMP, what is used for data parallelisation? What is used for task parallelisiation?

A

Loop splitting (parallel for)

Sections & tasks (task farm)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Are the following variables shared or private:
a. Variable declared inside parallel region
b. Variable declared outside parallel region

A

a. shared
b. private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are some ways that OpenMP allows for coordination between threads?

A

 barrier
 nowait
 omp_(un)set_lock()
 critical
 atomic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the two types of loop scheduling for loop splitting in OpenMP?

A

schedule (static, #chunk_size): progress as fast as slowest thread

schedule (dynamic, #chunk_size):each thread processes a chunk of iterations

16
Q

How is the depend() clause used in a OpenMP task?

A

depend() clause defines a list of items that are input or output dependencies of the task.

The scheduler does not start a task that depends on a value not yet generated.

17
Q

How can the variable visibility be set in OpenMP?

A

private()
shared()
firstprivate(): initialised to original value