]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add cpp-taskflow quicktest
authorTimo Heister <timo.heister@gmail.com>
Thu, 28 May 2020 19:16:30 +0000 (15:16 -0400)
committerTimo Heister <timo.heister@gmail.com>
Sun, 31 May 2020 19:53:42 +0000 (15:53 -0400)
tests/quick_tests/CMakeLists.txt
tests/quick_tests/taskflow.cc [new file with mode: 0644]

index 774b17709cb1d82e96f324b1157ed1e84aa9775a..69d08dafc3564710d18a2745638ea688f244b0d1 100644 (file)
@@ -102,10 +102,15 @@ IF (DEAL_II_WITH_MPI)
 ENDIF()
 
 # Test if TBB works correctly
-IF (DEAL_II_WITH_THREADS)
+IF (DEAL_II_WITH_TBB)
   make_quicktest("tbb" ${_mybuild} "")
 ENDIF()
 
+# test cpp-taskflow
+IF (DEAL_II_WITH_CPP_TASKFLOW)
+  make_quicktest("taskflow" ${_mybuild} "")
+ENDIF()
+
 # Test p4est. This test exposes a bug in OpenMPI 1.3 and 1.4
 # Update to OpenMPI 1.5 or newer.
 IF (DEAL_II_WITH_P4EST)
diff --git a/tests/quick_tests/taskflow.cc b/tests/quick_tests/taskflow.cc
new file mode 100644 (file)
index 0000000..25747b5
--- /dev/null
@@ -0,0 +1,83 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+// test cpp-taskflow
+
+#include <deal.II/base/thread_management.h>
+
+DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
+#include <taskflow/taskflow.hpp>
+DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
+
+#include <iostream>
+
+using namespace dealii;
+
+void
+test1()
+{
+  auto &executor = MultithreadInfo::get_taskflow_executor();
+
+  std::atomic<unsigned int> counter;
+  counter = 0;
+
+  tf::Taskflow taskflow;
+
+  auto incrementor = [&]() { counter.fetch_add(1); };
+
+
+  tf::Task A = taskflow.emplace(incrementor);
+  tf::Task B = taskflow.emplace(incrementor);
+  tf::Task C = taskflow.emplace([&]() {
+    std::cout << "counter = " << counter << std::endl;
+    counter = 0;
+  });
+
+  A.precede(C);
+  B.precede(C);
+
+  auto p =
+    taskflow.parallel_for(1, 11, 1, [&](int idx) { counter.fetch_add(idx); });
+
+  C.precede(p.first);
+
+  executor.run(taskflow).wait();
+
+  if (counter != 55)
+    {
+      std::cout << "error: counter is " << counter << " and not 55."
+                << std::endl;
+      exit(1);
+    }
+
+  taskflow.dump(std::cout);
+}
+
+
+
+int
+main()
+{
+  MultithreadInfo::set_thread_limit();
+
+  std::cout << "cpp-taskflow will use "
+            << MultithreadInfo::get_taskflow_executor().num_workers()
+            << " out of " << MultithreadInfo::n_cores() << " cores."
+            << std::endl
+            << "MultithreadInfo::n_thread()= " << MultithreadInfo::n_threads()
+            << std::endl;
+
+  test1();
+}

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.