2. (Performance of Tridiagonal Solvers) The objective of this exercise is to improve the performance of the
Question:
2. (Performance of Tridiagonal Solvers)
The objective of this exercise is to improve the performance of the tridiagonal solvers.
Answer the following questions:
a) Consider using move semantics instead of copy constructors when initialising the arrays in the solvers.
b) For the Thomas algorithm can we ‘sacrifice’ one or more of the input arrays to reduce the number of internal work arrays?
c) We can consider using specialised (your favourite) memory managers, as the following example shows:
// Double Sweep with a memory allocator
/*#include
#include
DoubleSweep
mySolver3
(a,
b, c, r, BCL, BCR);
Vector result = mySolver3();
auto exact = [](double x) { return x*(1.0 - x); };
double val = 0;
// Compare output from Double Sweep and Thomas for (std::size_t j = 0; j < result.size(); ++j)
{ // The values should be zero std::cout << j << ", " << result[j] << ", " << exact(val);
val += h;
}
Run the code and compare the run-time performance with the default C++ allocator.
d) Most of the examples in this book use tridiagonal matrices of size 1000 at most. Is there any point trying to improve the run-time performance by parallelising the code using threads or tasks? Consider starting and stopping threads; the multithreaded code may have worse performance than the sequential code. We discuss parallel programming in Chapters 28 to 30.
Step by Step Answer: