OpenMP Flashcards

1
Q

When was OpenMP first introduced for Fortran and C/C++?

A
  • Fortran: October 1997
  • C/C++: October 1998
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the latest version of OpenMP? When was it released?

A

Version 6.0, released in November 2024.

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

What are the three main ways OpenMP extends C, C++, and Fortran?

A
  1. Compiler Directives
  2. Environment Variables
  3. Runtime Library Routines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the OpenMP fork-join execution model.

A

Execution starts with a single master thread, which forks worker threads in parallel regions and joins them back at the end.

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

How do you include an OpenMP directive in C/C++?

A

#pragma omp directive [clause1, ...]

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

How do you create a parallel region in OpenMP?

A

#pragma omp parallel

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

What compiler flag is required for OpenMP in GCC?

A

-fopenmp

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

How can you control the number of threads used in OpenMP?

A

Set the OMP_NUM_THREADS environment variable (e.g., export OMP_NUM_THREADS=4).

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

What happens if the number of threads is not specified?

A

The implementation chooses a default value.

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

What does the OpenMP runtime library provide?

A

Functions for:
- Execution Environment Control
- Timing
- Device Memory Management
- Locking

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

Name three OpenMP functions that query execution environment details.

A
  1. omp_get_thread_num(): Returns the thread number
  2. omp_get_num_threads(): Returns the total number of threads
  3. omp_get_num_procs(): Returns the number of available processors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What header file must be included to use OpenMP functions in C?

A

#include <omp.h>

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

Why would conditional compilation be needed for OpenMP programs?

A

To allow compilation without OpenMP support, enabling serial execution.

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

What preprocessor directive is used for conditional compilation in OpenMP?

A

#ifdef _OPENMP

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

How can you conditionally include OpenMP-specific code?

A
#ifdef _OPENMP
include <omp.h>
endif
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the _OPENMP macro indicate?

A

It is defined only when OpenMP is enabled during compilation.

17
Q

Why is loop parallelisation important in OpenMP?

A

It allows work to be divided among threads, improving performance.

18
Q

What directive is used to parallelise a loop inside a parallel region?

A

#pragma omp for

19
Q

How do you combine parallel region creation and loop parallelisation?

A

#pragma omp parallel for

20
Q

What are the two types of variable scoping in OpenMP?

A
  1. Shared: A variable is accessible by all threads
  2. Private: Each thread has its own copy of the variable
21
Q

How can you explicitly define variable scope in OpenMP?

A

Use the default, private, and shared clauses in OpenMP directives.

22
Q

What does default(none) do in OpenMP?

A

It forces all variables to be explicitly declared as private or shared.

23
Q

What issue occurs when multiple threads modify a shared variable simultaneously?

A

A data race, which can lead to incorrect results.

24
Q

How can you safely sum values in parallel?

A

Use a reduction variable:
#pragma omp for reduction(+ : sum)

25
What is a data dependency?
A situation where the execution of one statement depends on another, potentially causing issues in parallel execution.
26
What are the three types of loop-carried dependencies?
1. **Flow Dependency (Read after Write):** Later iterations depend on earlier ones. 2. **Anti-dependency (Write after Read):** Later iterations overwrite values needed by earlier ones. 3. **Output Dependency (Write after Write):** Multiple iterations write to the same memory location.
27
What OpenMP feature helps retain the last computed value in a parallel loop?
The `lastprivate` clause
28
What does `lastprivate(x)` do?
Ensures that the value of `x` from the last loop iteration is preserved after the parallel region ends.