-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfarm.tex
83 lines (79 loc) · 2.79 KB
/
farm.tex
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
\subsection{Farm of tasks}
\begin{frame}[t]{Farm pattern}
\begin{itemize}
\item A \textgood{farm} is a streaming pattern applicable to a stage in a \textmark{pipeline},
providing multiple tasks to process data items from a data stream.
\begin{itemize}
\item A \textmark{farm} has an associated \textgood{cardinality} which is the number of parallel
tasks used to serve the stage.
\item Each task in a \textmark{farm} runs a \textgood{transformer} for each data item it receives.
\end{itemize}
\end{itemize}
\vfill
\begin{center}
\begin{tikzpicture}
\tikzset{
label/.style={text centered, text=orange,font=\footnotesize,minimum width=1cm} ,
transform/.style={rectangle,rounded corners,draw=black,fill=green!50,text=white,thick, text centered, font=\tiny, minimum width=0.75cm,minimum height=0.5cm},
item/.style={rectangle,draw=black,fill=orange!70,text=white,thick, text centered, font=\tiny, minimum width=0.75cm},
result/.style={rectangle,draw=black,fill=blue!70,text=white,thick, text centered, font=\tiny, minimum width=0.75cm},
arrow/.style={->,thick,draw=black,font=\tiny},
}
\node[transform] (stage0) {};
\node[transform, right=1cm of stage0] (stage1) {};
\node[transform,right=1cm of stage1] (stage2a) {};
\node[transform,above=0.5cm of stage2a] (stage2b) {};
\node[transform,below=0.5cm of stage2a] (stage2c) {};
\node[transform,right=1cm of stage2a] (stage3) {};
\node[transform,right=1cm of stage3] (stage4) {};
%
\path[arrow] (stage0) -- (stage1);
\path[arrow] (stage1) -- (stage2a);
\path[arrow] (stage1) -- (stage2b);
\path[arrow] (stage1) -- (stage2c);
\path[arrow] (stage2a) -- (stage3);
\path[arrow] (stage2b) -- (stage3);
\path[arrow] (stage2c) -- (stage3);
\path[arrow] (stage3) -- (stage4);
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}[t,fragile]{Farms in pipelines: Improving a video}
\begin{lstlisting}
template <typename Execution>
void run_pipe(const Execution & ex,
std::ifstream & filein, std::ofstream & fileout)
{
grppi::pipeline(ex,
[&filein] () -> optional<frame> {
frame f = read_frame(filein);
if (!filein) retrun {};
return f;
},
farm(4, [](const frame & f) { return improve(f); },
[&fileout] (const frame & f) { write_frame(f); }
);
}
\end{lstlisting}
\end{frame}
\begin{frame}[t,fragile]{Piecewise farms: Improving a video}
\vspace{-1.25em}
\begin{lstlisting}
template <typename Execution>
void run_pipe(const Execution & ex,
std::ifstream & filein, std::ofstream & fileout)
{
auto improver = farm(4,
[](const frame & f) { return improve(f); });
grppi::pipeline(ex,
[&filein] () -> optional<frame> {
frame f = read_frame(filein);
if (!filein) retrun {};
return f;
},
improver,
[&fileout] (const frame & f) { write_frame(f); }
);
}
\end{lstlisting}
\end{frame}