<p>Cpp-Taskflow is a fast C++ <em>header-only</em> library to help you quickly write parallel programs with complex task dependencies. Cpp-Taskflow is by far faster, more expressive, fewer lines of code, and easier for drop-in integration than existing parallel task programming libraries such as <ahref="http://www.nersc.gov/users/software/programming-models/openmp/openmp-tasking/">OpenMP Tasking</a> and Intel <ahref="https://www.threadingbuildingblocks.org/tutorial-intel-tbb-flow-graph">Thread Building Block (TBB) FlowGraph</a>.</p>
<p>Cpp-Taskflow is committed to support both academic and industry research projects, making it reliable and cost-effective for long-term and large-scale developments. Our users say:</p>
<ul>
<li>"<em>Cpp-Taskflow has the cleanest task API I've ever seen.</em>" <ahref="https://github.com/damienhocking">Damien Hocking</a></li>
<li>"<em>Cpp-Taskflow has a very simple and elegant tasking interface. The performance also scales very well.</em>" <ahref="https://github.com/totalgee">Glen Fraser</a></li>
<li>"<em>Cpp-Taskflow lets me handle parallel processing in a smart way.</em>" <ahref="https://cpp-learning.com/cpp-taskflow/">Hayabusa</a></li>
<li>"<em>Best poster award for the open-source parallel programming library.</em>" <ahref="https://github.com/CppCon/CppCon2018">Cpp Conference 2018</a></li>
</ul>
<p>See a quick <ahref="https://cpp-taskflow.github.io/">presentation</a> and visit our <ahref="https://github.com/cpp-taskflow/cpp-taskflow">GitHub</a> to learn more about Cpp-Taskflow.</p>
<p>Cpp-Taskflow is <em>header-only</em> and there is no need for installation. Simply download the source and copy the headers under the <code>taskflow</code> subdirectory to your project.</p>
<divclass="fragment"><divclass="line">~$ git clone https://github.com/cpp-taskflow/cpp-taskflow.git</div><divclass="line">~$ cd cpp-taskflow/</div><divclass="line">~$ cp -r taskflow myproject/include/</div></div><!-- fragment --><h1><aclass="anchor" id="ASimpleFirstProgram"></a>
A Simple First Program</h1>
<p>Here is a rather simple program to get you started.</p>
<divclass="fragment"><divclass="line"><spanclass="preprocessor">#include <taskflow/taskflow.hpp></span><spanclass="comment">// Cpp-Taskflow is header-only</span></div><divclass="line"></div><divclass="line"><spanclass="keywordtype">int</span> main(){</div><divclass="line"></div><divclass="line"><aclass="code" href="classtf_1_1Executor.html">tf::Executor</a> executor;</div><divclass="line"><aclass="code" href="classtf_1_1Taskflow.html">tf::Taskflow</a> taskflow;</div><divclass="line"></div><divclass="line"><spanclass="keyword">auto</span> [A, B, C, D] = taskflow.<aclass="code" href="classtf_1_1FlowBuilder.html#a4d52a7fe2814b264846a2085e931652c">emplace</a>(</div><divclass="line"> [] () { <aclass="codeRef" doxygen="/home/tsung-wei/Code/cpp-taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <spanclass="stringliteral">"TaskA\n"</span>; }, <spanclass="comment">// task dependency graph</span></div><divclass="line"> [] () { <aclass="codeRef" doxygen="/home/tsung-wei/Code/cpp-taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <spanclass="stringliteral">"TaskB\n"</span>; }, <spanclass="comment">// </span></div><divclass="line"> [] () { <aclass="codeRef" doxygen="/home/tsung-wei/Code/cpp-taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <spanclass="stringliteral">"TaskC\n"</span>; }, <spanclass="comment">// +---+ </span></div><divclass="line"> [] () { <aclass="codeRef" doxygen="/home/tsung-wei/Code/cpp-taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <spanclass="stringliteral">"TaskD\n"</span>; } <spanclass="comment">// +---->| B |-----+ </span></div><divclass="line"> ); <spanclass="comment">// | +---+ |</span></div><divclass="line"><spanclass="comment">// +---+ +-v-+ </span></div><divclass="line"> A.<aclass="code" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(B); <spanclass="comment">// A runs before B // | A | | D | </span></div><divclass="line"> A.<aclass="code" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(C); <spanclass="comment">// A runs before C // +---+ +-^-+ </span></div><divclass="line"> B.<aclass="code" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(D); <spanclass="comment">// B runs before D // | +---+ | </span></div><divclass="line"> C.<aclass="code" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(D); <spanclass="comment">// C runs before D // +---->| C |-----+ </span></div><divclass="line"><spanclass="comment">// +---+ </span></div><divclass="line"> executor.<aclass="code" href="classtf_1_1Executor.html#a81f35d5b0a20ac0646447eb80d97c0aa">run</a>(taskflow).wait();</div><divclass="line"></div><divclass="line"><spanclass="keywordflow">return</span> 0;</div><divclass="line">}</div></div><!-- fragment --><p>The program creates four tasks A, B, C, and D. The dependency constraints force A to run before B and C, and D to run after B and C. The maximum concurrency is this example is two, where B and C can run at the same time.</p>
<p>Cpp-Taskflow is written in C++17 and is built on top of C++ standardized threading libraries. To compile the above program, you need to tell the compiler where to find the Cpp-Taskflow header files. For example, with gcc you need the <code>-I</code> option.</p>
<divclass="fragment"><divclass="line">~$ g++ simple.cpp -I myproject/include/ -std=c++17 -O2 -pthread -o simple</div><divclass="line">~$ ./simple</div><divclass="line">TaskA</div><divclass="line">TaskC </div><divclass="line">TaskB </div><divclass="line">TaskD</div></div><!-- fragment --><p>The execution order of B and C might differ as they can run concurrently.</p>
<h1><aclass="anchor" id="SupportedCompilers"></a>
Supported Compilers</h1>
<p>To use Cpp-Taskflow, you only need a compiler that supports C++17:</p>
<ul>
<li>GNU C++ Compiler v7.3 with -std=c++17 </li>
<li>Clang C++ Compiler v6.0 with -std=c++17 </li>
<li>Microsoft Visual Studio Version 15.7 (MSVC++ 19.14)</li>
</ul>
<p>Cpp-Taskflow works on Linux, Windows, and OSX.</p>
<h1><aclass="anchor" id="License"></a>
License</h1>
<p>Cpp-Taskflow is open-source under permissive MIT license. </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<divid="nav-path" class="navpath"><!-- id is needed for treeview function! -->