From 921b29fd456c21ad2b28eeaf35a84861eb3cb010 Mon Sep 17 00:00:00 2001 From: guido Date: Tue, 4 May 1999 22:12:28 +0000 Subject: [PATCH] small speed test for LAC git-svn-id: https://svn.dealii.org/trunk@1270 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/lac/Makefile | 18 ++++++++- tests/lac/benchmark.cc | 61 ++++++++++++++++++++++++++++ tests/lac/quickmatrix.h | 89 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 tests/lac/benchmark.cc create mode 100644 tests/lac/quickmatrix.h diff --git a/tests/lac/Makefile b/tests/lac/Makefile index 1b7ce6c299..5206a20f89 100644 --- a/tests/lac/Makefile +++ b/tests/lac/Makefile @@ -105,6 +105,22 @@ mg: $(mg-o-files) $(libraries) ############################################################ +benchmark-cc-files = benchmark.cc + +ifeq ($(debug-mode),on) +benchmark-o-files = $(benchmark-cc-files:.cc=.go) +else +benchmark-o-files = $(benchmark-cc-files:.cc=.o) +endif + +benchmark: $(benchmark-o-files) $(libraries) + $(CXX) $(flags) -o $@ $^ + +############################################################ +# Continue with other targets if needed +############################################################ + + target1-cc-files = t1.cc t2.cc t3.cc ifeq ($(debug-mode),on) @@ -132,7 +148,7 @@ veryclean: clean # Automatic generation of dependencies ############################################################ -all-cc-files = $(solver-cc-files) $(mgbase-cc-files) $(mg-cc-files) # $(target2-cc-files) ... +all-cc-files = $(solver-cc-files) $(mgbase-cc-files) $(mg-cc-files) $(benchmark-cc-files) Make.depend: $(all-cc-files) @echo =====Dependecies=== Make.depend diff --git a/tests/lac/benchmark.cc b/tests/lac/benchmark.cc new file mode 100644 index 0000000000..30ac1b5453 --- /dev/null +++ b/tests/lac/benchmark.cc @@ -0,0 +1,61 @@ +// $Id$ + + +#include +#include +#include "quickmatrix.h" +#include + +#define ITER 100 +main() +{ + Vector u; + Vector v; + + clock_t start; + clock_t diff; + + deallog << "Iterations: " << ITER << endl; + + for (unsigned int nx=32; nx<8192 ; nx*=2) + { + const unsigned int dim=(nx-1)*(nx-1); + + deallog << "size = " << nx << " dim = " << dim << endl; + + start = clock(); + for (unsigned int i=0;i A(nx,nx); + + start = clock(); + for (unsigned int i=0;i +class QuickMatrix +{ +public: + /** + * Constructor initializing the grid size. + */ + QuickMatrix(unsigned int nx, unsigned int ny); + + /** + * Matrix-vector-product. + */ + template + void vmult(Vector&, const Vector&) const; +protected: + const unsigned int nx; + const unsigned int ny; +}; + + +template +QuickMatrix::QuickMatrix(unsigned int nx, unsigned int ny) + : +nx(nx), ny(ny) +{} + +template +template +void +QuickMatrix::vmult(Vector& d, + const Vector& s) const +{ + const unsigned int step = nx-1; + const unsigned int right = step-1; + const unsigned int top = ny-1; + + // Bottom row + + d(0) = s(0) - .25 * ( s(1) + s(step) ); + + for (unsigned int x=1; x