Homework 03
Fall 2021
CISC 372
Student Name: ____________Fanchao Meng________________
Please put your screenshots or copy-and-paste text output into the provided tables.
GOAL: To record time taken for serial Vs OpenMP codes that uses atomic, critical and reduction clauses TOTAL – 70 points (Question 1 – 7)
Use the sync_constructs.c in Canvas (File-> code as a starting point)
1) Write a serial code in C (or C++) 15 points
a. Initialize the variable “i” and another variable sum among any other variables you want to initialize.
b. Create a for loop with “i” ranging from 0 through 123456789.
c. Iteratively (within the for loop) add to sum = sum + a[i]
d. 2 points Use the time header file to time the for loop
e. 4 points Use the NVIDIA HPC SDK and GNU GCC compilers available on Bridges2 to compile the code. Add screenshots of the compilation steps. 1 for NVIDIA HPC and 1 for GNU GCC.
f. 2 points Create a batch script (like you have been for HW01 and HW02) to execute the code. DO NOT execute the code on the login node
Add a screenshot of your batch script.
g. 2 points Your output should read “My serial code took ———- seconds”. (Add the seconds you will see on your terminal once you have compiled and executed the code) Add a screenshot of your output.
h. 5 points Add your full code here
#
Response
1E
1F
1G
1H
2) Now use the same serial code 15 points
a. This time add an OpenMP atomic clause to the for loop
b. 2 points Use the time header file to time the for loop with the atomic clause
c. 4 points Use the NVIDIA HPC SDK and GNU GCC compilers available on Bridges2 to compile the code. Use the appropriate OpenMP flags else your code will not be running in parallel. Add screenshots of the compilation steps. 1 for NVIDIA HPC and 1 for GNU GCC.
d. 2 points Create a batch script (like you have been for HW01 and HW02) to execute the code. DO NOT execute the code on the login node Add a screenshot of your batch script.
e. 2 points Your output should read “My atomic code took ———- seconds”. (Add the seconds you will see on your terminal once you have compiled and executed the code) Add a screenshot of your output.
f. 5 points Add your full code here
#
Response
2C
2D
2E
2F
3) Now use the same serial code once again 15 points
a. This time add an OpenMP critical clause to the for loop
b. 2 points Use the time header file to time the for loop with the critical clause
c. 4 points Use the NVIDIA HPC SDK and GNU GCC compilers available on Bridges2 to compile the code. Use the appropriate OpenMP flags else your code will not be running in parallel. Add screenshots of the compilation steps. 1 for NVIDIA HPC and 1 for GNU GCC.
d. 2 points Create a batch script (like you have been for HW01 and HW02) to execute the code. DO NOT execute the code on the login node Add a screenshot of your batch script.
e. 2 points Your output should read “My critical code took ———- seconds”. (Add the seconds you will see on your terminal once you have compiled and executed the code) Add a screenshot of your output.
f. 5 points Add your full code here
#
Response
3C
3D
3E
3F
4) Now use the same serial code once again 15 points
a. This time add an OpenMP reduction clause to the for loop
b. 2 points Use the time header file to time the for loop with the reduction clause
c. 4 points Use the NVIDIA HPC SDK and GNU GCC compilers available on Bridges2 to compile the code. Use the appropriate OpenMP flags else your code will not be running in parallel. Add screenshots of the compilation steps.. 1 for NVIDIA HPC and 1 for GNU GCC.
d. 2 points Create a batch script (like you have been for HW01 and HW02) to execute the code. DO NOT execute the code on the login node Add a screenshot of your batch script.
e. 2 points Your output should read “My reduction code took ———-seconds”. (Add the seconds you will see on your terminal once you have compiled and executed the code) Add a screenshot of your output.
f. 5 points Add your full code here
#
Response
4C
4D
4E
4F
5) 5 points Fill this table.
Code Versions
Time in seconds (NVHPC)
Time in seconds (GNU GCC)
Serial Version
Atomic Version
Critical Version
Reduction Version
6) 4 points Summarize what you observe. Which version of the 4 codes performed better than the rest and why do you think that happened?
Your response here…
7) 1 point In your opinion, which of the 2 compilers performed better for the reduction clause?
Your response here…
8) GOAL: To parallelize a cube problem 30 points
20 points Parallelize the cube problem. Pick up the code from Canvas, Files -> Code -> cubes.zip
10 points Note down the time taken for the 2 compilers in the table below.
Cube Versions
Time in seconds (NVHPC)
Time in seconds (GNU GCC)
Serial time
Parallel threads
2
4
8
16
2
4
8
16
Parallel time
NOTE:
· Use the makefile to run the code for both serial and parallel versions.
· The code is timed using the time(1) command. It will report time like so:
63.96 real
60.25 user
0.81 sys
Please report the user time in the table above.