Activity: Numerical integration
The purpose of this assignment is for you to
- get started back in writing C or C++ code
- get familiar with running code on mamba
- write a simple program that will be reused in future assignments
As usual all time measurements are to be performed on the cluster.
1 Numerical Integration
Numerical integration is often used when one wants to computebut one does not know how to find a primitive of f. You can use the definition of integration to obtain a simple approximation by computing is often called the number of point in the approximation. (This is the
numerical integration using the rectangle rule. You can learn more at https://en.wikipedia.org/wiki/
The provided package contains multiple functions to integrate in libfunctions.a. The functions are named f1, f2, f3, f4, and take two parameters: the first one is a floating point number x where the function is computed, and the second one is intensity an operation intensity. The second parameter is used to make the function take more time.
The code you should write should take 5 command line parameters:
- functionid, an integer to know which function to integrate. If functionid is 1, integrate f1; If functionid is 2, integrate f2; etc.
- a, the lower bound of the integral
- b, the upper bound of the integral
- n, an integer which is the number of points to compute the approximation of the integral
- intensity, an integer which is the second parameter to give the the function to integrate. You will see that in the scaffold f1 takes two parameter, an x, and an intensity. Use that parameter as intensity.
The code should compute the integral and output the value of the integral on stdout (and nothing else). The code should also measure the time it took to compute the integral and write that time (expressed in seconds with decimal values) to stderr (and nothing else).
Question: Write the described code. You can use the provided archive as a template. It contain a template code and makefile to help you write the code. You should only need to complete main.cpp. You should be able to test if your code is correct using make test.
2 Benchmarking on mamba
Question: Report the time it takes on the cluster to integrate f1 using different number of points (from 101 to 108) and with different operation intensity (from 1 to 104). To help you in that task, you should be able to run make bench which should run the benchmark in a PBS job. Once that job is completed, you can draw charts using make plot which reports time in a pdf file plot/time plots.pdf.
Make sure you keep this code around as it is your base for comparisons in future assignments.
1
FAQ
Do I need to understand how integration works?
Not really. The assignment is really about evaluating that particular expression. You dont need to understand why that is an integration operation. The problem is just to evaluate for a particular combination of a, b, n, and f.
I cant find the code of function f1, f2, f3, f4 ?!
Indeed, you dont have access to them. You do not need access to the code of functions f1, f2, f3, and f4. These functions are in libfunctions.a.
When I compile, it does not find function f1.
Do not compile by hand, use make.
When I run make bench, it tells me qsub command not found.
You need to run make bench on mamba.
When I run make bench, it tells me I need to pass the tests.
You need to have successfully run make test.
How long will the job take to run?
The job may run on a mamba compute node for about an hour. (Depending on how the code is written). Note that you dont need to stay logged on mamba. Once the job is batched, mamba will eventually run it.
How should I measure time?
Use std::chrono::system clock. Check cpprefence.
I get error: unrecognized command line option -std=c++17 when compiling on mamba Add module load gcc at the end of your /.bashrc on mamba.
Reviews
There are no reviews yet.