From 51c64479f5fa0453bc1d3aef51e15cbb57cf33aa Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Thu, 28 May 2020 15:16:30 -0400 Subject: [PATCH] add cpp-taskflow quicktest --- tests/quick_tests/CMakeLists.txt | 7 ++- tests/quick_tests/taskflow.cc | 83 ++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 tests/quick_tests/taskflow.cc diff --git a/tests/quick_tests/CMakeLists.txt b/tests/quick_tests/CMakeLists.txt index 774b17709c..69d08dafc3 100644 --- a/tests/quick_tests/CMakeLists.txt +++ b/tests/quick_tests/CMakeLists.txt @@ -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 index 0000000000..25747b529f --- /dev/null +++ b/tests/quick_tests/taskflow.cc @@ -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_DISABLE_EXTRA_DIAGNOSTICS +#include +DEAL_II_ENABLE_EXTRA_DIAGNOSTICS + +#include + +using namespace dealii; + +void +test1() +{ + auto &executor = MultithreadInfo::get_taskflow_executor(); + + std::atomic 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(); +} -- 2.39.5