School of Physics & Astronomy
Parallel Programming Languages PGPH11072 (SCQF Level 11)
Thursday 15th December, 2016 14:30 – 16:30 (December Diet)
Please read full instructions before commencing writing. Examination Paper Information
Copyright By PowCoder代写 加微信 powcoder
Special Instructions
• Electronic Calculators must not be used during this examination.
• Attach supplied anonymous bar codes to each script book. Special Items
• School supplied barcodes
Chairman of Examiners: Prof A S Trew External Examiner: Prof Simon McIntosh- of the candidate will be maintained during the marking of this examination.
Answer ALL the questions
Each question must be answered in a separate book, question number clearly marked
Printed: Wednesday 30th November, 2016
Parallel Programming Languages (PGPH11072)
1. Fortran2008allowsyoutooutputdatausingbothformattedandunformattedI/O.Give
two differences between these types of I/O and give an example of where you might use
each type of I/O. [6]
Static and dynamic arrays are commonly used in Fortran 2008. Discuss the advantages
and disadvantages of each approach. Give an example of how you would declare and allocate a three-dimensional dynamic array of floating point numbers with 5, 25 and 100 elements in the first, second and third dimensions respectively. How would you declare
the same array statically? [9]
Given the following code snippet, what would be the output from the following 5 write statements? You should briefly explain how you obtained your answer for each.
integer, dimension(3,5) :: a
a = reshape( (/-1,0,2,5,8,0,1,-5,-3,2,10,2,0,5,-3/), (/3,5/) )
write(*,*) a
write(*,*) a(:,2)
write(*,*) maxval(a, mask = a < 10)
write(*,*) transpose(a(1:3,1:3))
write(*,*) product(a, mask = a > 0, dim = 2)
Printed: Wednesday 30th November, 2016 Page 1 Continued overleaf. . .
Parallel Programming Languages (PGPH11072)
2. ACUDAapplicationhasbeenwrittentoutiliseUnifiedMemory.Thefollowingstepsare
performed:
a. An array is allocated using cudaMallocManaged.
b. Initialisation is performed using regular (non-CUDA) code.
c. The data is processed by the GPU, using a CUDA kernel.
In which memory space does the data reside for each of these three steps? Describe how
these steps could be adapted to use manual memory management instead. [8] State one advantage and one disadvantage of the use of Unified Memory in real applica-
tions. [2] Describe in detail how to ensure that optimal memory bandwidth can be achieved for
GPU kernels. [5] Describe in detail why it is important to ensure that there are many more CUDA threads
than GPU cores. [5] Explain why deep learning has rapidly increased in popularity over the last few years,
and why the methods are well suited to GPUs. [5]
Printed: Wednesday 30th November, 2016 Page 2 Continued overleaf. . .
Parallel Programming Languages (PGPH11072)
3. For each of the four UPC variable definitions below, state where each element of x will reside with respect to memory space and thread affinity. Assume that the compilation is static and there are 4 threads.
• int x[8];
• shared int x[8];
• shared [*] int x[8]; • shared [3] int x[8];
Consider the code below. Assuming static compilation and 4 threads, describe why this code will fail to compile, and what change you could make to fix it.
#include
#include
int main(){
shared int x[8];
return 0; }
[5] mation. What is this additional information? [2]
You are working in a small company. Your boss asks you to port some legacy serial C code to UPC to increase efficiency. She provides you with a cut-down version of a code to port (below) so she can see the impact of the port before proceeding with the rest of the code. She has four requirements:
a. UPC features should be used where possible;
b. each thread must perform an equal volume of work to the single thread in the serial version;
c. it must be suitable for dynamic compilation;
d. structural changes should be minimized where possible.
Assume that the initialisation function init arrays is defined in the header init fns.h and is not thread safe.
Write an updated version of the following code, compatible with her requirements:
UPC pointers are in many ways similar to C pointer but they contain additional infor-
Printed: Wednesday 30th November, 2016 Page 3 Continued overleaf. . .
Parallel Programming Languages (PGPH11072)
#define N 100
#include
#include “init_fns.h”
int main(){
init_arrays(&a[0], &b[0], &c[0]);
for(i=0;i
if (implus2 > num_images()) implus2 = implus2 – num_images()
y(:) = this_image()
x(4) = y(3)[implus1]
y(5)[implus2] = x(4)+10
write(*,*) “x(4), y(3), y(5) = “, x(4), y(3), y(5)
Four of these lines alter the values of the x or y arrays; state clearly what each of these
lines does. [6]
In general, PGAS approaches require explicit synchronisation to ensure that communica-
tions takes place correctly. Explain clearly what synchronisation calls are required in this program, and where they should be placed. [6]
If the program is run on 4 images, what will the output be from image 3? You should
briefly explain your answer. [6]
Describe how this communications pattern could be achieved using the OpenSHMEM library, considering array declarations, communications and synchronisation. You can consider either C or Fortran, but you do not need to be concerned about details of syntax.
Printed: Wednesday 30th November, 2016 Page 5 End of Paper
Parallel Programming Languages (PGPH11072) Invigilators Information
Delivered papers 30 minutes prior to start time. 1. Course information
2. Exam diet / paper information
3. Invigilators Instructions
4. Stationery Requirement Stationery: 4 x 8 sides script books.
5. Items to be handed out with exam papers
6. Additional Information
• None Notes:
Course title: Course No: Academic : Secretary: School:
Parallel Programming Languages PGPH11072
Dr Alan Gray
Joan of Physics & Astronomy
Contact No: Contact No: Contact No:
07762750419 07879283559 50-7218 / 51-7067
Date of exam: Location of exam: No of exam papers:
Thursday 15th December, 2016 Time of exam: 14:30 – 16:30 – Room 5327
Unissued paper returned: Yes Answer on exam paper: No Answer on MCQ : No Used exam papers returned: No
Approved Calculators : Open Book Exam: Script book per answer: Dictionary allowed:
See rubric No
Calculators (from School): No Bar Codes (from School): Yes Graph paper (from School: No Bibles (from School): No Formula Sheets (from School): No
Printed: Wednesday 30th November, 2016 School of Physics and Astronomy
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com