Skip to content

Commit a581ade

Browse files
committed
updated named_async
1 parent dc64219 commit a581ade

44 files changed

Lines changed: 2421 additions & 726 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/AsyncTasking.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ <h3>Contents</h3>
7575
<span class="p">})</span>
7676
<span class="p">});</span>
7777
<span class="n">executor</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="n">taskflow</span><span class="p">);</span>
78-
<span class="n">executor</span><span class="p">.</span><span class="n">wait_for_all</span><span class="p">();</span> <span class="c1">// wait for all tasks to finish</span></pre><aside class="m-note m-info"><h4>Note</h4><p>Asynchronous tasks created from an executor does not belong to any taskflows.</p></aside></section><section id="LaunchAsynchronousTasksFromAnSubflow"><h2><a href="#LaunchAsynchronousTasksFromAnSubflow">Launch Asynchronous Tasks from a Subflow</a></h2><p>You can launch asynchronous tasks from a subflow (<a href="classtf_1_1Subflow.html" class="m-doc">tf::<wbr />Subflow</a>) using <a href="classtf_1_1Subflow.html#a70681068507b224a96df69cc1f3168f1" class="m-doc">tf::<wbr />Subflow::<wbr />async</a>. Asynchronous tasks created from a subflow are, and <em>only</em>, used with <em>join</em> (<a href="classtf_1_1Subflow.html#a59fcac1323e70d920088dd37bd0be245" class="m-doc">tf::<wbr />Subflow::<wbr />join</a>) to describe independent tasks that are dynamically spawned during the execution of that subflow. When the subflow joins, all asynchronous tasks are guaranteed to finish. The following code creates 100 asynchronous tasks from a subflow, and these asynchronous tasks will complete by the time the subflow joins.</p><pre class="m-code"><span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span> <span class="n">taskflow</span><span class="p">;</span>
78+
<span class="n">executor</span><span class="p">.</span><span class="n">wait_for_all</span><span class="p">();</span> <span class="c1">// wait for all tasks to finish</span></pre><aside class="m-note m-info"><h4>Note</h4><p>Asynchronous tasks created from an executor does not belong to any taskflows.</p></aside><p>You can name an asynchronous task to facilitate profiling by using the methods <a href="classtf_1_1Executor.html#a51acee1670e9f246c7ccd7f6a63f1524" class="m-doc">tf::<wbr />Executor::<wbr />named_async</a> and <a href="classtf_1_1Executor.html#a1febfaa7a99cac8466263c58fd2a7c06" class="m-doc">tf::<wbr />Executor::<wbr />named_silent_async</a>.</p><pre class="m-code"><span class="n">tf</span><span class="o">::</span><span class="n">Future</span><span class="o">&lt;</span><span class="kt">void</span><span class="o">&gt;</span> <span class="n">future</span> <span class="o">=</span> <span class="n">executor</span><span class="p">.</span><span class="n">named_async</span><span class="p">(</span><span class="s">&quot;name of the task&quot;</span><span class="p">,</span> <span class="p">[](){});</span>
79+
<span class="n">executor</span><span class="p">.</span><span class="n">silent_named_async</span><span class="p">(</span><span class="s">&quot;another name of the task&quot;</span><span class="p">,</span> <span class="p">[](){});</span></pre></section><section id="LaunchAsynchronousTasksFromAnSubflow"><h2><a href="#LaunchAsynchronousTasksFromAnSubflow">Launch Asynchronous Tasks from a Subflow</a></h2><p>You can launch asynchronous tasks from a subflow (<a href="classtf_1_1Subflow.html" class="m-doc">tf::<wbr />Subflow</a>) using <a href="classtf_1_1Subflow.html#a70681068507b224a96df69cc1f3168f1" class="m-doc">tf::<wbr />Subflow::<wbr />async</a>. Asynchronous tasks created from a subflow are, and <em>only</em>, used with <em>join</em> (<a href="classtf_1_1Subflow.html#a59fcac1323e70d920088dd37bd0be245" class="m-doc">tf::<wbr />Subflow::<wbr />join</a>) to describe independent tasks that are dynamically spawned during the execution of that subflow. When the subflow joins, all asynchronous tasks are guaranteed to finish. The following code creates 100 asynchronous tasks from a subflow, and these asynchronous tasks will complete by the time the subflow joins.</p><pre class="m-code"><span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span> <span class="n">taskflow</span><span class="p">;</span>
7980
<span class="n">tf</span><span class="o">::</span><span class="n">Executor</span> <span class="n">executor</span><span class="p">;</span>
8081

8182
<span class="n">std</span><span class="o">::</span><span class="n">atomic</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span> <span class="n">counter</span><span class="p">{</span><span class="mi">0</span><span class="p">};</span>
@@ -102,7 +103,11 @@ <h3>Contents</h3>
102103
<span class="n">assert</span><span class="p">(</span><span class="n">counter</span> <span class="o">==</span> <span class="mi">100</span><span class="p">);</span>
103104
<span class="p">});</span>
104105

105-
<span class="n">executor</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="n">taskflow</span><span class="p">).</span><span class="n">wait</span><span class="p">();</span></pre><p>Creating asynchronous tasks from a subflow allows users to describe, for example, recursive algorithms that define only division without conquering or merging (e.g., parallel quick sort).</p><aside class="m-note m-warning"><h4>Attention</h4><p>You should only create asynchronous tasks from a joined subflow. Launching asynchronous tasks from a detached subflow results in undefined behavior.</p></aside></section>
106+
<span class="n">executor</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="n">taskflow</span><span class="p">).</span><span class="n">wait</span><span class="p">();</span></pre><p>Creating asynchronous tasks from a subflow allows users to describe, for example, recursive algorithms that define only division without conquering or merging (e.g., parallel quick sort).</p><aside class="m-note m-warning"><h4>Attention</h4><p>You should only create asynchronous tasks from a joined subflow. Launching asynchronous tasks from a detached subflow results in undefined behavior.</p></aside><p>Similar to <a href="classtf_1_1Executor.html#a51acee1670e9f246c7ccd7f6a63f1524" class="m-doc">tf::<wbr />Executor::<wbr />named_async</a> and <a href="classtf_1_1Executor.html#a1febfaa7a99cac8466263c58fd2a7c06" class="m-doc">tf::<wbr />Executor::<wbr />named_silent_async</a>, you can name an asynchronous task in <a href="classtf_1_1Subflow.html" class="m-doc">tf::<wbr />Subflow</a> to facilitate profiling by using the methods <a href="classtf_1_1Subflow.html#ae528c2de98ec89afc50b8815c0306b5e" class="m-doc">tf::<wbr />Subflow::<wbr />named_async</a> and <a href="classtf_1_1Subflow.html#a3290b8f729c4511f2023199e4c067951" class="m-doc">tf::<wbr />Subflow::<wbr />named_silent_async</a>.</p><pre class="m-code"><span class="n">taskflow</span><span class="p">.</span><span class="n">emplace</span><span class="p">([](</span><span class="n">tf</span><span class="o">::</span><span class="n">Subflow</span><span class="o">&amp;</span> <span class="n">sf</span><span class="p">){</span>
107+
<span class="n">tf</span><span class="o">::</span><span class="n">Future</span><span class="o">&lt;</span><span class="kt">void</span><span class="o">&gt;</span> <span class="n">future</span> <span class="o">=</span> <span class="n">sf</span><span class="p">.</span><span class="n">named_async</span><span class="p">(</span><span class="s">&quot;name of the task&quot;</span><span class="p">,</span> <span class="p">[](){});</span>
108+
<span class="n">sf</span><span class="p">.</span><span class="n">silent_named_async</span><span class="p">(</span><span class="s">&quot;another name of the task&quot;</span><span class="p">,</span> <span class="p">[](){});</span>
109+
<span class="n">sf</span><span class="p">.</span><span class="n">join</span><span class="p">();</span>
110+
<span class="p">});</span></pre></section>
106111
</div>
107112
</div>
108113
</div>

docs/annotated.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h1>Classes</h1>
6565
<li>class <a href="classtf_1_1cudaTask.html" class="m-doc">cudaTask</a> <span class="m-doc">handle to a node of the internal CUDA graph</span></li>
6666
<li>class <a href="classtf_1_1Executor.html" class="m-doc">Executor</a> <span class="m-doc">class to create an executor for running a taskflow graph</span></li>
6767
<li>class <a href="classtf_1_1FlowBuilder.html" class="m-doc">FlowBuilder</a> <span class="m-doc">class to build a task dependency graph</span></li>
68-
<li>class <a href="classtf_1_1Future.html" class="m-doc">Future</a> <span class="m-doc">class to access the result of task execution</span></li>
68+
<li>class <a href="classtf_1_1Future.html" class="m-doc">Future</a> <span class="m-doc">class to access the result of an execution</span></li>
6969
<li>class <a href="classtf_1_1ObserverInterface.html" class="m-doc">ObserverInterface</a> <span class="m-doc">The interface class for creating an executor observer.</span></li>
7070
<li>class <a href="classtf_1_1Semaphore.html" class="m-doc">Semaphore</a> <span class="m-doc">class to create a semophore object for building a concurrency constraint</span></li>
7171
<li>class <a href="classtf_1_1Subflow.html" class="m-doc">Subflow</a> <span class="m-doc">class to construct a subflow graph from the execution of a dynamic task</span></li>

0 commit comments

Comments
 (0)