Vector Addition¶
1. In the parallelized version of the vector addition function using OpenACC, which directive is used to offload the code block to the GPU?
- A.
#pragma acc parallel - B.
#pragma acc data - C.
#pragma acc kernels - D.
#pragma acc async
Click to reveal the answer
Answer: C. `#pragma acc kernels`Data Movement and Memory Allocation¶
2. Which data clause in OpenACC is used to transfer data from the host (CPU) to the device (GPU) at the beginning of a parallel region?
- A.
copyout - B.
copyin - C.
create - D.
present
Click to reveal the answer
Answer: B. `copyin`3. True or False: The copyout clause in OpenACC ensures that the results of a computation on the GPU are transferred back to the CPU after the parallel region completes.
Click to reveal the answer
Answer: TrueLoop Parallelization¶
4. In the OpenACC parallelized version of vector addition, the loop clause is used to:
- A. Create memory on the GPU
- B. Specify that the loop should be parallelized across GPU threads
- C. Transfer data from the GPU to the CPU
- D. Sequentially execute the loop
Click to reveal the answer
Answer: B. Specify that the loop should be parallelized across GPU threadsAvoiding Pointer Aliasing¶
5. True or False: The restrict keyword in C/C++ tells the compiler that pointers do not overlap in memory, allowing for safer and more efficient parallelization.