14#include "../Utils_Fill.h"
23 cout <<
"=== Matrix: compare access speeds to native array ===\n";
26 const std::size_t L = 10000;
34 B =
new double[ L * L ];
40 for ( std::size_t row = 0; row < L; ++row ) {
41 for ( std::size_t col = 0; col < L; ++col ) {
42 B[ row * L + col ] = A( row, col );
43 M( row, col, 0 ) = A( row, col );
47 cout <<
" DenseMatrix<double> scaling on a per-element basis via access operator.\n";
50 for ( std::size_t row = 0; row < L; ++row ) {
51 for ( std::size_t col = 0; col < L; ++col ) {
60 cout <<
"\n TwoD_Node_Mesh<double> scaling on a per-element basis via access operator.\n";
62 for ( std::size_t row = 0; row < L; ++row ) {
63 for ( std::size_t col = 0; col < L; ++col ) {
64 M( row, col, 0 ) *= 2.0;
72 cout <<
"\n Native array scaling on a per-element basis.\n";
74 for ( std::size_t row = 0; row < L; ++row ) {
75 for ( std::size_t col = 0; col < L; ++col ) {
76 B[ row * L + col ] *= 2.0;
86 cout <<
"The % slow-down for a DenseMatrix was " <<
87 100.0 * ( timeA - timeB ) / ( 0.5 * ( timeA + timeB ) ) <<
"\n";
89 cout <<
"The % slow-down for a TwoD_Node_Mesh was " <<
90 100.0 * ( timeM - timeB ) / ( 0.5 * ( timeM + timeB ) ) <<
"\n";
94 if ( ( timeA - timeB ) / ( 0.5 * ( timeA + timeB ) ) > 0.05 ) {
96 cout <<
"The % slow-down for a DenseMatrix was " <<
97 100.0 * ( timeA - timeB ) / ( 0.5 * ( timeA + timeB ) ) <<
"\n";
100 if ( std::abs( timeM - timeB ) / ( 0.5 * ( timeM + timeB ) ) > 0.05 ) {
102 cout <<
"The % slow-down for a TwoD_Node_Mesh was " <<
103 100.0 * ( timeM - timeB ) / ( 0.5 * ( timeM + timeB ) ) <<
"\n";
107 cout <<
"\033[1;31;48m * FAILED \033[0m\n";
110 cout <<
"\033[1;32;48m * PASSED \033[0m\n";
A spec for the CppNoddy Timer object.
A specification for a two dimensional mesh object.
A spec for a collection of utility functions.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
An DenseVector class – a dense vector object.
A simple CPU-clock-tick timer for timing metods.
double get_time() const
Return the time.
void start()
Start the timer & reset stored time to zero.
void print() const
Write a string to cout stating the time taken.
void stop()
Stop the clock & add the current time interval to the previously stored values ready for printing.
void reset()
Pause the clock & add the time interval to the stored cumulative time.
A two dimensional mesh utility object.
DenseVector< double > uniform_node_vector(const double &lower, const double &upper, const std::size_t &N)
Return a DENSE vector with the nodal points of a uniform mesh distributed between the upper/lower bou...
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...
void fill_random(CppNoddy::SparseVector< double > &V, const unsigned &num_of_elts)