-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgraphviz.cpp
More file actions
85 lines (67 loc) · 2.22 KB
/
graphviz.cpp
File metadata and controls
85 lines (67 loc) · 2.22 KB
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
82
83
84
85
/***************** GRAPHVIZ EXAMPLE ***************/
// Last update: 13/08/2020
//
// In this example we show how you can use easyDAG to
// visualize your DAG scheme using DOT.
// We set a name to each step (the default value is
// just "Task").
// In the example we create two vectors starting
// from just a dimension size; we fill the two
// vectors; we concatenate them and we apply a
// sum reduction.
// The DAG is written in the stdout in the DOT
// format so if you want to visualize the png
// you can re-direct the stdout to a file and
// use the command:
// $> dot -Tpng graph.dot > output.png
//
/***************************************************/
#include <easyDAG.hpp>
#include <numeric>
#include <cassert>
#include <iostream>
#include <algorithm>
int main ()
{
const int N = 10;
const std :: string pipeline_name = "pipeline";
auto init = [](const int & N) -> std :: vector < float >
{
std :: vector < float > x(N);
return x;
};
auto fill = [](std :: vector < float > x) -> std :: vector < float >
{
std :: fill(x.begin(), x.end(), 1.f);
return x;
};
auto concat = [](std :: vector < float > x, std :: vector < float > y)
{
std :: vector < float > res(x.size() + y.size());
std :: copy_n(x.begin(), x.size(), res.begin());
std :: copy_n(y.begin(), y.size(), res.begin() + x.size());
return res;
};
auto reduce = [](std :: vector < float > res)
{
return std :: accumulate(res.begin(), res.end(), 0.f);
};
auto size = InputVariable(N);
size.set_name(size);
Task init_x(init, size);
Task init_y(init, size);
init_x.set_name(init_x);
init_y.set_name(init_y);
Task fill_x(fill, init_x);
Task fill_y(fill, init_y);
fill_x.set_name(fill_x);
fill_y.set_name(fill_y);
Task concatenate(concat, fill_x, fill_y);
concatenate.set_name(concatenate);
Task reduction(reduce, concatenate);
reduction.set_name(reduction);
reduction.graphviz(std :: cout, pipeline_name);
reduction.eval();
assert ( reduction() == N * 2 );
return 0;
}