|
Uni20
Asynchronous tensor and runtime library.
|
Example of using uni20 coroutines with the TbbScheduler to parallelize a map–reduce computation. More...
#include <iostream>#include <numeric>#include <uni20/async/async.hpp>#include <uni20/async/buffers.hpp>#include <uni20/async/tbb_scheduler.hpp>#include <vector>Functions | |
| int | main () |
| AsyncTask | square (ReadBuffer< int > in, WriteBuffer< int > out) |
| AsyncTask | sum (ReadBuffer< int > a, ReadBuffer< int > b, WriteBuffer< int > out) |
Example of using uni20 coroutines with the TbbScheduler to parallelize a map–reduce computation.
This example computes the sum of squares from 1 to N using two coroutine kernels:
square: squares a single integersum: sums two integersThe computation is structured in two phases:
square coroutines over all inputssum coroutinesThe scheduler (TbbScheduler) manages coroutine resumption across threads participating in its arena, while Async<int>, ReadBuffer<int>, and WriteBuffer<int> handle dataflow and dependency tracking between tasks.
This demonstrates:
Expected output (for N=1000):
In principle the application thread can reach the last line of main() before any of the scheduled computations begin.
| int main | ( | ) |
| AsyncTask square | ( | ReadBuffer< int > | in, |
| WriteBuffer< int > | out | ||
| ) |
| AsyncTask sum | ( | ReadBuffer< int > | a, |
| ReadBuffer< int > | b, | ||
| WriteBuffer< int > | out | ||
| ) |