Introduction to OpenMP¶
1. Which directive in OpenMP is used to parallelize a for
loop by distributing its iterations across multiple threads?
- A.
#pragma omp simd
- B.
#pragma omp parallel
- C.
#pragma omp parallel for
- D.
#pragma omp private
Click to reveal the answer
Answer: C. `#pragma omp parallel for`Shared Memory Architecture¶
2. In OpenMP, which data-sharing attribute ensures that each thread has its own instance of a variable, with no sharing across threads?
- A.
shared
- B.
private
- C.
reduction
- D.
collapse
Click to reveal the answer
Answer: B. `private`3. True or False: OpenMP is specifically designed for shared memory architectures where multiple processing cores can access the same main memory space.
Click to reveal the answer
Answer: TrueSIMD and Memory Optimization¶
4. Which OpenMP directive is used to optimize a loop for SIMD instructions on compatible hardware?
- A.
#pragma omp parallel
- B.
#pragma omp simd
- C.
#pragma omp for
- D.
#pragma omp task
Click to reveal the answer
Answer: B. `#pragma omp simd`Practical Usage in C/C++ and Fortran¶
5. True or False: In OpenMP, the reduction
clause combines values from multiple threads (e.g., summing values) in a way that ensures data consistency and prevents race conditions.
Click to reveal the answer
Answer: True6. In Fortran, which directive would you use to parallelize a loop similar to OpenMP's #pragma omp parallel for
in C/C++?
- A.
!$omp for
- B.
!$omp private
- C.
!$omp parallel do
- D.
!$omp simd