-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskflow.cc
81 lines (59 loc) · 1.88 KB
/
taskflow.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// ------------------------------------------------------------------------
//
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (C) 2020 - 2023 by the deal.II authors
//
// This file is part of the deal.II library.
//
// Part of the source code is dual licensed under Apache-2.0 WITH
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
// governing the source code and code contributions can be found in
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
//
// ------------------------------------------------------------------------
// test taskflow
#include <deal.II/base/thread_management.h>
#include <taskflow/algorithm/for_each.hpp>
#include <taskflow/taskflow.hpp>
#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.for_each_index(1, 11, 1, [&](int idx) { counter.fetch_add(idx); });
C.precede(p);
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 << "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();
}