Parallel Computing with OpenMP Flashcards

1
Q

What is a “thread?”

A

A thread is a lightweight unit of execution within a program. When a program runs in parallel using OpenMP, it creates multiple threads that work concurrently. Each thread executes a portion of the code simultaneously. This can greatly speed up computations by taking advantage of multiple CPU cores.

Think of threads as “workers” that perform parts of a larger task simultaneously. The thread ID helps you identify which worker is executing a specific piece of code.

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

What is the “master thread?”

A

Typically, thread 0 is used as the master thread, which often handles tasks like gathering results or printing overall information (like the total number of threads).

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

What is a “core” with respect to computing?

A

A core is essentially an independent processing unit within your CPU. It contains the necessary components (like arithmetic logic units, registers, and caches) to execute instructions and perform computations.

In parallel programming, such as with OpenMP, cores act as the “workers” that execute threads. While hyper-threading can create additional logical cores, the physical cores are where the actual computations take place.

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

Describe the reduction clause in OpenMP.

A

The reduction clause in OpenMP is a mechanism to safely perform operations that combine values from multiple threads, such as summing elements of an array, without running into race conditions.

When running loops in parallel, each thread might calculate a partial result that needs to be combined into a single final value (like a sum, product, or even logical operations). Without reduction, concurrent writes to a shared variable (e.g., updating a running sum) could lead to race conditions where the results interfere with each other.

With the reduction clause, OpenMP automatically creates a private copy of the variable for each thread. These private copies are initialized to an identity value for the operation (for example, 0 for addition, 1 for multiplication). Each thread then performs its computation on its private copy. Once all threads complete their portion of the loop, OpenMP combines (or “reduces”) these individual values using the specified operator and stores the final result in the original shared variable.

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