File: parallel_pipeline_func.htm

package info (click to toggle)
tbb 4.2~20140122-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 21,492 kB
  • ctags: 21,278
  • sloc: cpp: 92,813; ansic: 9,775; asm: 1,070; makefile: 1,057; sh: 351; java: 226; objc: 98; pascal: 71; xml: 41
file content (139 lines) | stat: -rwxr-xr-x 6,893 bytes parent folder | download
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns:MSHelp="http://www.microsoft.com/MSHelp/" lang="en-us" xml:lang="en-us"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="DC.Type" content="reference">
<meta name="DC.Title" content="parallel_pipeline Function">
<meta name="DC.subject" content="Range Concept">
<meta name="keywords" content="Range Concept">
<meta name="DC.Relation" scheme="URI" content="../../reference/algorithms.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/algorithms/parallel_pipeline_func/filter_t_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/algorithms/parallel_pipeline_func/flow_control_cls.htm">
<meta name="DC.Relation" scheme="URI" content="pipeline_cls.htm">
<meta name="DC.Relation" scheme="URI" content="../task_scheduler/task_group_context.htm">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="parallel_pipeline_func">
<meta name="DC.Language" content="en-US">
<link rel="stylesheet" type="text/css" href="../../intel_css_styles.css">
<title>parallel_pipeline Function</title>
<xml>
<MSHelp:Attr Name="DocSet" Value="Intel"></MSHelp:Attr>
<MSHelp:Attr Name="Locale" Value="kbEnglish"></MSHelp:Attr>
<MSHelp:Attr Name="TopicType" Value="kbReference"></MSHelp:Attr>
</xml>
</head>
<body id="parallel_pipeline_func">
 <!-- ==============(Start:NavScript)================= -->
 <script src="..\..\NavScript.js" language="JavaScript1.2" type="text/javascript"></script>
 <script language="JavaScript1.2" type="text/javascript">WriteNavLink(2);</script>
 <!-- ==============(End:NavScript)================= -->
<a name="parallel_pipeline_func"><!-- --></a>


<h1 class="topictitle1">parallel_pipeline Function</h1>

     

<div>
    <div class="section"><h2 class="sectiontitle">Summary</h2> Strongly typed interface for pipelined execution. </div>

    <div class="section"><h2 class="sectiontitle">Header</h2> 
<pre>#include "tbb/pipeline.h"</pre>
 </div>

 <div class="section"><h2 class="sectiontitle">Syntax</h2> 
<pre>void parallel_pipeline( size_t max_number_of_live_tokens, 
                        const filter_t&lt;void,void&gt;&amp; filter_chain
                        [, task_group_context&amp; group] );
</pre></div>

 <div class="section"><h2 class="sectiontitle">Description</h2>
            <p> Function <samp class="codeph">parallel_pipeline</samp> is a strongly typed lambda-friendly
                interface for building and running pipelines. The pipeline has characteristics
                similar to class <samp class="codeph">pipeline</samp>, except that the stages of the pipeline
                are specified via functors instead of class derivation.</p>

            <p>To build and run a pipeline from functors <em>g</em><sub>0</sub>, <em>g</em><sub>1</sub>, 
	    <em>g</em><sub>2</sub>, ..., <em>g</em><sub>n</sub>, write:</p>

            <pre>parallel_pipeline( max_number_of_live_tokens, 
                   make_filter&lt;void,I1&gt;(mode0,g0) &amp;
                   make_filter&lt;I1,I2&gt;(mode1,g1) &amp;
                   make_filter&lt;I2,I3&gt;(mode2,g2) &amp;
                   ... 
                   make_filter&lt;In,void&gt;(moden,gn) );
</pre><p>In
                general, functor <em>g</em><sub>i</sub> should define its <samp class="codeph">operator()</samp> to map objects of type
                    <em>I</em><sub>i</sub> to objects of type <em>I</em><sub>i+1</sub>. Functor <em>g</em><sub>0</sub> is a special case, because it notifies the pipeline when the end of the
                input stream is reached. Functor <em>g</em><sub>0</sub> must be defined such that for a flow_control object <em>fc</em>, the
                expression <em>g</em><sub>0</sub> (<em>fc</em> ) either returns the next value in the input stream, or if
                at the end of the input stream, invokes <em>fc.</em>stop() and returns a dummy
                value.</p>
 The value <em>max_number_of_live_tokens</em> has the same meaning as it
            does for <samp class="codeph">pipeline::run</samp>. <p> If the group argument is specified,
                pipeline's tasks are executed in this group. By default the algorithm is executed in
                a bound group of its own. </p>
</div>

    <div class="section"><h2 class="sectiontitle">Example</h2>
     <p> The following example uses <samp class="codeph">parallel_pipeline</samp> compute
                the root-mean-square of a sequence defined by [ <em>first</em> , <em>last</em> ). The
                example is only for demonstrating syntactic mechanics. It is not as a practical way
                to do the calculation because parallel overhead would be vastly higher than useful
                work. Operator &amp; requires that the output type of its first
                    <samp class="codeph">filter_t</samp> argument matches the input type of its second
                    <samp class="codeph">filter_t</samp> argument.</p>
<pre>float RootMeanSquare( float* first, float* last ) {
    float sum=0;
    parallel_pipeline( /*max_number_of_live_token=*/16,       
        make_filter&lt;void,float*&gt;(
            filter::serial,
            [&amp;](flow_control&amp; fc)-&gt; float*{
                if( first&lt;last ) {
                    return first++;
                 } else {
                    fc.stop();
                    return NULL;
                }
            }    
        ) &amp;
        make_filter&lt;float*,float&gt;(
            filter::parallel,
            [](float* p){return (*p)*(*p);} 
        ) &amp;
        make_filter&lt;float,void&gt;(
            filter::serial,
            [&amp;](float x) {sum+=x;}
        )
    );
    return sqrt(sum);
}
     </pre><p>See the Intel&reg; Threading Building Blocks Tutorial for a non-trivial example
                of <samp class="codeph">parallel_pipeline</samp>.</p>

     </div>


</div>


<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong>&nbsp;<a href="../../reference/algorithms.htm">Algorithms</a></div>
</div>
<div class="See Also">
<ul class="ullinks">
<li class="ulchildlink"><a href="../../reference/algorithms/parallel_pipeline_func/filter_t_cls.htm">filter_t Template Class</a><br>
</li>
<li class="ulchildlink"><a href="../../reference/algorithms/parallel_pipeline_func/flow_control_cls.htm">flow_control Class</a><br>
</li>
</ul>

<h2>See Also</h2>
<div class="linklist">
<div><a href="pipeline_cls.htm">pipeline Class 
		  </a></div>
<div><a href="../task_scheduler/task_group_context.htm">task_group_context</a></div></div>
</div>
</body>
</html>