]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
small speed test for LAC
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 4 May 1999 22:12:28 +0000 (22:12 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 4 May 1999 22:12:28 +0000 (22:12 +0000)
git-svn-id: https://svn.dealii.org/trunk@1270 0785d39b-7218-0410-832d-ea1e28bc413d

tests/lac/Makefile
tests/lac/benchmark.cc [new file with mode: 0644]
tests/lac/quickmatrix.h [new file with mode: 0644]

index 1b7ce6c299adb20814f967a6192d40ee25c09c34..5206a20f89b9648f22ae97e4660ac550d44b0525 100644 (file)
@@ -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 (file)
index 0000000..30ac1b5
--- /dev/null
@@ -0,0 +1,61 @@
+// $Id$
+
+
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include "quickmatrix.h"
+#include <time.h>
+
+#define ITER 100
+main()
+{
+  Vector<double> u;
+  Vector<double> 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<ITER;i++)
+       {
+         u.reinit(dim);
+         v.reinit(dim);
+       }
+      diff = clock()-start;
+      deallog << "reinit: " << double(diff)/(2*ITER) << endl;
+
+      start = clock();
+      for (unsigned int i=0;i<ITER;i++)
+       {
+         u = (double) i;
+       }
+      diff = clock()-start;
+      deallog << "operator=(double): " << double(diff)/ITER << endl;
+
+      QuickMatrix<double> A(nx,nx);
+
+      start = clock();
+      for (unsigned int i=0;i<ITER;i++)
+       {
+         A.vmult(v,u);
+       }
+      diff = clock()-start;
+      deallog << "vmult: " << double(diff)/ITER << endl;
+    }
+}
+
+
+
+
+
+
+
+
diff --git a/tests/lac/quickmatrix.h b/tests/lac/quickmatrix.h
new file mode 100644 (file)
index 0000000..18af4f6
--- /dev/null
@@ -0,0 +1,89 @@
+// $Id$
+
+/**
+ * Hard-coded Laplacian matrix.
+ * Just a quick matrix to investigate processor performance.
+ * It implements a finite difference scheme on a grid of grid size 1
+ * with #nx# times #ny# grid points.
+ * The diagonal is scaled to 1, resulting in an effective mesh width of 1/2.
+ */
+
+template<typename number>
+class QuickMatrix
+{
+public:
+  /**
+   * Constructor initializing the grid size.
+   */
+  QuickMatrix(unsigned int nx, unsigned int ny);
+
+  /**
+   * Matrix-vector-product.
+   */
+  template <typename number2>
+  void vmult(Vector<number2>&, const Vector<number2>&) const;
+protected:
+  const unsigned int nx;
+  const unsigned int ny;
+};
+
+
+template<typename number>
+QuickMatrix<number>::QuickMatrix(unsigned int nx, unsigned int ny)
+  :
+nx(nx), ny(ny)
+{}
+
+template<typename number>
+template <typename number2>
+void
+QuickMatrix<number>::vmult(Vector<number2>& d,
+                          const Vector<number2>& 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<right; ++x)
+    d(x) = s(x) - .25 * ( s(x-1) + s(x+1) + s(x+step) );
+
+  d(right) = s(right) - .25 * ( s(right-1) + s(right+step) );
+
+  // Middle rows
+
+  unsigned int start = 0;
+  for (unsigned int y=1; y<top; y++)
+    {
+      start += step;
+      d(start) = s(start)
+       - .25 * ( s(start-step) + s(start+1) + s(start+step) );
+      
+      for (unsigned int x=1; x<right; ++x)
+       {
+         const unsigned int xy = start+x;
+         d(xy) = s(xy)
+           - .25 * ( s(xy-step) + s(xy-1) + s(xy+1) + s(xy+step) );
+       }
+      d(start+right) = s(start+right)
+       - .25 * ( s(start+right-1) + s(start+right+step) );
+    }
+  
+  // Top row
+
+  start += step;
+  d(start) = s(start)
+    - .25 * ( s(start-step) + s(start+1) );
+
+  for (unsigned int x=1; x<right; ++x)
+    {
+      const unsigned int xy = start+x;
+      d(xy) = s(xy)
+       - .25 * ( s(xy-step) + s(xy-1) + s(xy+1) );
+    }
+  d(start+right) = s(start+right)
+    - .25 * ( s(start+right-step) + s(start+right-1) );
+}

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.