• Keine Ergebnisse gefunden

“Object-Oriented Programming for Scientific Computing”

N/A
N/A
Protected

Academic year: 2021

Aktie "“Object-Oriented Programming for Scientific Computing”"

Copied!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

IWR, Heidelberg University Summer Semester 2015

Exercise Sheet 8 02. 06. 2015

Exercises for the Lecture Series

“Object-Oriented Programming for Scientific Computing”

Ole Klein

ole.klein@iwr.uni-heidelberg.de

To be handed in on 09. 06. 2015 before the lecture

EXERCISE1 STATIC VS.DYNAMIC POLYMORPHISM

We want to investigate runtime differences of programs when using static or dynamic polymor- phism. As an example we again consider the numerical integration program.

Instead of using dynamic polymorphism, we may also select the quadrature rule and/or the function to be integrated using static polymorphism (templates).

1. Write three additional variants of the integration program you have already developed, with the following features:

(a) Static selection of the quadrature rule, dynamic selection of the function.

(b) Dynamic selection of the quadrature rule, static selection of the function.

(c) Static selection of the quadrature rule, static selection of the function.

2. Measure the time required for integration in the four main routines. Use the<chrono>header for this, it provides a namespace std::chrono with timer functionality. Try to familiarize yourself with this header, here is an example on how to use it:

const auto start = std::chrono::high_resolution_clock::now();

// compute integral here

const auto end = std::chrono::high_resolution_clock::now();

const auto ms = std::chrono::duration_cast<std::chrono::nanoseconds>

(end-start).count() / 1000.;

// ms contains elapsed time in milliseconds // print it using std::cout, for example

3. Measure the time for all four versions, once without optimization (compiler option “-O0”) and once with optimization (compiler option “-O3”). Use the integration ofR13

−32t2+ 5with 100.000 nodes as a test case. Measure both the Simpson and the trapezoidal rule, and fill a table with the results.

4. Are there time differences between the different versions? Interpret and justify the results! Is it worth it to think about the form of polymorphism in this situation? If so, why? If not, why not?

20 Points

Referenzen

ÄHNLICHE DOKUMENTE

• Traits can be used to specify types and values that depend on one or more template parameters. • Policies can be used to specify parts of algorithms as

Since the units are only used as a template parameter, this only affects the class type but does not require memory... Example: Numbers

This header also contains functions that provide a thread ID and the functionality to detach threads that afterwards run as a separate program (fork).. Mutual Exclusion The header

and no exercise group, because things are still being set up, but you are welcome to attend if you have questions about the lecture or exercises or something else to discuss.. E

~List (); // clean up the list and all nodes Node* first() const; // return a pointer to the first entry Node* next( const Node* n) const; // return a pointer to the node after n

Please modify your implementation again to obtain a doubly linked list: each element should also point to its predecessor.. What is

To understand why the size of empty classes (according to standard) is as observed, consider the following class!. struct

Modify the method operator[], so that erroneous access results in an exception being thrown (comparable to the behavior of the method std::vector&lt;T&gt;::at instead