Skip to main content
NHR Learning Platform
  • Home
  • Calendar
  • More
You are currently using guest access
Log in
NHR Learning Platform
Home Calendar
Expand all Collapse all
  1. Dashboard
  2. PTfS22
  3. 2 May - 8 May
  4. Assignment 0: Warming up (due May 6)

Assignment 0: Warming up (due May 6)

Completion requirements
Opened: Thursday, 21 April 2022, 12:00 AM
Due: Friday, 6 May 2022, 12:00 PM

Write a benchmark code that numerically computes the integral

\( \displaystyle\int\limits_0^1\frac{4}{1+x^2}\,\mathrm{d}x \).

The result should be an approximation to \( \pi \), of course. You may use a very simple rectangular integration scheme that works by summing up areas of rectangles centered around  \( x_i \) with a width of \( \Delta x \) and a height of \( f(x_i) \):

int SLICES = 1000000000;
double sum=0., delta_x = ....;
for (int i=0; i < SLICES; i++) {<br></strong><strong> double x = (i+0.5)*delta_x;<br></strong><strong> sum += (4.0 / (1.0 + x * x));<br></strong><strong>}
double Pi = sum * delta_x;

Complete the code fragment (translate to FORTRAN if you wish), add suitable timing functions to measure the runtime of the main loop (as described in the tutorials kick-off),  make sure that it actually computes an approximation to \( \pi \), and run it on one core of the Fritz cluster. Use the Intel compiler with the recommended compiler options (-O3 -xHost). Include the relevant parts of your code in your submission. Do not forget to fix the clock speed (use 2 GHz).

  1. (40 credits) How many CPU cycles does the code take to execute per iteration of the loop? Describe how you arrived at this number from your measurements!
  2. (20 credits) What is the performance of the code? Is Flops/s a good performance metric here? Discuss different options for appropriate performance metrics in this code.
  3. (20 credits) Discuss what happens (in terms of performance and accuracy) if you change the code to use single-precision floating-point numbers! Are there any relevant code changes beyond data types? Why do you not get a reasonable accuracy for \( \pi \)? (Please submit your single-precision code as well).
  4. (20 credits) Run the (double-precision) experiment again, but this time do not fix the clock frequency. Calculate the actual frequency the CPU was running at.
Actually, this code can be used to measure the duration of a floating-point divide because the divide operation dominates its runtime. Everything else can be "hidden" behind the divide.

Note: How to fix the clock speed has been described in the first tutorial session. To reiterate: You have to run your executable with the srun command as a wrapper and using the --cpu-freq option:

srun --cpu-freq=2000000-2000000 ./a.out
If you want to run this experiment in a job script, this is a possible template:

#!/bin/bash -l
#
#SBATCH --nodes=1
#SBATCH --time=00:08:00
#SBATCH --job-name=pi
#SBATCH --export=NONE
#
# first non-empty non-comment line ends SBATCH options
module load intel
echo Hello World!
srun --cpu-freq=2000000-2000000 ./a.out
 

Adding the --cpu-freq option to the sbatch command at job submission will not fix the clock frequency. You have to use it with srun.

You are currently using guest access (Log in)
Data retention summary
Powered by Moodle