]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
add multithreaded function_parser test
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 6 Feb 2014 16:17:55 +0000 (16:17 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 6 Feb 2014 16:17:55 +0000 (16:17 +0000)
git-svn-id: https://svn.dealii.org/trunk@32420 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/function_parser_04.cc [new file with mode: 0644]
tests/base/function_parser_04.with_functionparser=true.output [new file with mode: 0644]

diff --git a/tests/base/function_parser_04.cc b/tests/base/function_parser_04.cc
new file mode 100644 (file)
index 0000000..461522a
--- /dev/null
@@ -0,0 +1,100 @@
+// ---------------------------------------------------------------------
+// $Id$
+//
+// Copyright (C) 2005 - 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// functionparser: TBB
+
+#include "../tests.h"
+#include <fstream>
+#include <iomanip>
+#include <map>
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/point.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/base/function_parser.h>
+#include <deal.II/base/thread_management.h>
+#include <deal.II/base/work_stream.h>
+
+
+FunctionParser<2> fp;
+
+struct scratch_data
+{
+};
+
+struct copy_data
+{
+    int value;
+    copy_data():
+                   value(0)
+      {}
+    
+};
+
+
+void assemble(const std::vector<int>::iterator &it,
+              scratch_data &scratch,
+              copy_data &data)
+{
+  double s = *it;
+  double value = fp.value(Point<2>(s, 2.5));
+  Assert(abs(1.0+s*2.5 - value) < 1e-10, ExcMessage("wrong value"));
+  std::cout << data.value  << std::endl;
+  
+  data.value = (abs(1.0+s*2.5 - value) < 1e-10)?1:0;
+}
+
+void copy(int & value, const copy_data &data)
+{
+  value += data.value;
+}
+
+
+void test2()
+{
+  std::map<std::string, double> constants;
+  constants["c"]=1.0;
+  fp.initialize("s,t", "s*t+c", constants);
+
+  std::vector<int> v(10000);
+  for (unsigned int i=0;i<v.size();++i)
+    v[i] = i;
+
+  int result = 0;
+  WorkStream::run(v.begin(),
+                  v.end(),
+                  &assemble,
+                  std_cxx1x::bind(&copy,
+                                  std_cxx1x::ref(result),
+                                  std_cxx1x::_1),
+                  scratch_data(), copy_data());
+  std::cout << "result: " << result << std::endl;
+
+  Assert(result == v.size(), ExcMessage("uhuh!"));
+}
+
+
+int main ()
+{
+  initlog();
+
+  test2();
+}
+
+
+
+
diff --git a/tests/base/function_parser_04.with_functionparser=true.output b/tests/base/function_parser_04.with_functionparser=true.output
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +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.