Skip to content

Vector Addition with OpenMP Offloading

1. Which construct in OpenMP Offloading directly offloads a parallelized loop to the GPU with minimal control over team structure?

  • A. target parallel for
  • B. target teams distribute
  • C. target teams distribute parallel for
  • D. target parallel loop
Click to reveal the answer Answer: A. `target parallel for`

2. In OpenMP Offloading, what is the purpose of the map clause with to: a[0:n], b[0:n] in vector addition?

  • A. Copies the values of a and b from the device to the host at the end of execution.
  • B. Allocates memory on the device for a and b without any data transfer.
  • C. Transfers a and b from the host to the device before the target region begins.
  • D. Performs a reduction on a and b.
Click to reveal the answer Answer: C. Transfers `a` and `b` from the host to the device before the target region begins.

3. Which of the following would be most appropriate if you want to control the number of teams created on the GPU during offloading?

  • A. #pragma omp target parallel for
  • B. #pragma omp teams distribute
  • C. #pragma omp teams distribute parallel for num_teams(5)
  • D. #pragma omp target teams
Click to reveal the answer Answer: C. `#pragma omp teams distribute parallel for num_teams(5)`

4. True or False: The target teams distribute parallel for construct in OpenMP Offloading allows distribution of work across both teams and threads on the GPU.

Click to reveal the answer Answer: True

5. In OpenMP Offloading, which construct would allow you to create a "league of teams" on the GPU, where each team executes a portion of a parallelized loop?

  • A. target
  • B. parallel
  • C. target teams distribute
  • D. target parallel for
Click to reveal the answer Answer: C. `target teams distribute`

6. In the Fortran example, which construct offloads a parallel loop directly to the GPU without creating teams?

  • A. !$omp teams distribute
  • B. !$omp target parallel do
  • C. !$omp target teams distribute
  • D. !$omp parallel for
Click to reveal the answer Answer: B. `!$omp target parallel do`

7. Which OpenMP Offloading directive would you use to specify that five teams should be created on the device for executing a loop?

  • A. num_teams(5)
  • B. target parallel
  • C. map(tofrom: ...)
  • D. collapse(5)
Click to reveal the answer Answer: A. `num_teams(5)`

8. True or False: Using the teams construct without specifying parallel limits the offloading to team-level parallelism, without individual thread parallelism within each team.

Click to reveal the answer Answer: True

9. If you want to ensure that the result array c is available on the host after executing a vector addition on the GPU, which map clause should you use?

  • A. map(to: c[0:n])
  • B. map(from: c[0:n])
  • C. map(alloc: c[0:n])
  • D. map(tofrom: c[0:n])
Click to reveal the answer Answer: B. `map(from: c[0:n])`

10. What is the main advantage of using target teams distribute parallel for over target parallel for in OpenMP Offloading for vector addition?

  • A. It provides finer control over workload distribution across teams and threads.
  • B. It simplifies data mapping for host-device memory transfers.
  • C. It eliminates the need for OpenMP directives.
  • D. It restricts execution to the host CPU.
Click to reveal the answer Answer: A. It provides finer control over workload distribution across teams and threads.