User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ffnamespace:tutorial [2014/09/17 11:48]
torquati [The basic]
ffnamespace:tutorial [2015/09/08 16:52] (current)
torquati
Line 4: Line 4:
 ===== Tutorial ===== ===== Tutorial =====
  
-  * [[http://​calvados.di.unipi.it/​storage/​tutorial/​html/​tutorial.html|Single HTML file]] (version ​August 2014+  * [[http://​calvados.di.unipi.it/​storage/​tutorial/​html/​tutorial.html|Single HTML file]] (version ​September 2015
-  * [[http://​calvados.di.unipi.it/​storage/​tutorial/​fftutorial.pdf|PDF file]] (version ​August 2014)  +  * [[http://​calvados.di.unipi.it/​storage/​tutorial/​fftutorial.pdf|PDF file]] (version ​September 2015)  
-  * [[http://​calvados.di.unipi.it/​storage/​tutorial/​fftutorial_source_code.tgz | Tests and examples - source code tarball]] (version ​August 2014)+  * [[http://​calvados.di.unipi.it/​storage/​tutorial/​fftutorial_source_code.tgz | Tests and examples - source code tarball]] (version ​September 2015)
  
 ===== Very short Tutorial ===== ===== Very short Tutorial =====
Line 27: Line 27:
 <code c++> <code c++>
 /* this is a 3-stage pipeline example */ /* this is a 3-stage pipeline example */
 +#include <​iostream>​
 #include <​ff/​pipeline.hpp>​ #include <​ff/​pipeline.hpp>​
 using namespace ff; using namespace ff;
 typedef long fftask_t; typedef long fftask_t;
  
-struct firstStage: ff_node_t<​task_t> {+struct firstStage: ff_node_t<​fftask_t> {
     fftask_t *svc(fftask_t *t) {     fftask_t *svc(fftask_t *t) {
  for(long i=0;​i<​10;​++i) ff_send_out(new fftask_t(i));​  for(long i=0;​i<​10;​++i) ff_send_out(new fftask_t(i));​
Line 41: Line 42:
     return t;     return t;
 } }
-struct thirdStage: ff_node_t<​task_t> {+struct thirdStage: ff_node_t<​fftask_t> {
     fftask_t *svc(fftask_t *t) {     fftask_t *svc(fftask_t *t) {
  std::cout << "​stage"​ << get_my_id() << " received " << *t << "​\n";​  std::cout << "​stage"​ << get_my_id() << " received " << *t << "​\n";​
Line 49: Line 50:
 }; };
 int main() { int main() {
-    ​ff_pipe<fftask_t> pipe(new firstStage, secondStage, ​new thirdStage); +    ​ff_Pipe<> pipe(make_unique<​firstStage>(), 
-    ​pipe.cleanup_nodes(); // cleanup at exit+                   ​make_unique<​ff_node_F<​fftask_t>​ >(secondStage) 
 +                   ​make_unique<​thirdStage>(
 +                   ​);
     if (pipe.run_and_wait_end()<​0) error("​running pipe"​);​     if (pipe.run_and_wait_end()<​0) error("​running pipe"​);​
     return 0;     return 0;
Line 70: Line 73:
  
 int main() { int main() {
-    std::​vector<​ff_node*> W = {new thirdStage, new thirdStage}; // the farm has 2 workers +    std::vector<​std::​unique_ptr<ff_node> W; 
-    ​ff_pipe<fftask_t> pipe(new firstStage, secondStage, ​new ff_farm<>​(W)); +    ​// the farm has 2 workers 
-    ​pipe.cleanup_nodes();+    ​W.push_back( make_unique<​thirdStage>​());​ 
 +    W.push_back( make_unique<​thirdStage>​());​ 
 +     
 +    ff_Pipe<> pipe(make_unique<​firstStage>(), 
 +                   ​make_unique<​ff_node_F<​fftask_t>​ >(secondStage), 
 +                   ​make_unique<ff_Farm<​fftask_t> ​>(std::move(W)) 
 +                   ​);
     if (pipe.run_and_wait_end()<​0) error("​running pipe"​);​     if (pipe.run_and_wait_end()<​0) error("​running pipe"​);​
     return 0;     return 0;
Line 111: Line 120:
  
 As an example, considering the [[http://​en.wikipedia.org/​wiki/​Strassen_algorithm |Strassen'​s algorithm]] described by the following sequence of instructions operating on (sub-)matrices : As an example, considering the [[http://​en.wikipedia.org/​wiki/​Strassen_algorithm |Strassen'​s algorithm]] described by the following sequence of instructions operating on (sub-)matrices :
-S1 = A11 + A22S2 = B11 + B22S3 = A21 + A22S4 = B12 - B22S5 = B21 - B11 + 
-S6 = A11 + A12S7 = A21 - A11S8 = B11 + B12S9 = A12 - A22S10 = B21 + B22, +S1 = A11 + A22S2 = B11 + B22S3 = A21 + A22S4 = B12 - B22S5 = B21 - B11 
-P1 = S1 * S2P2 = S3 * B11P3 = A11 * S4P4 = A22 * S5P5 = S6 * B22P6 = S7 * S8P7  = S9*S10 +S6 = A11 + A12S7 = A21 - A11S8 = B11 + B12S9 = A12 - A22S10 = B21 + B22; 
-C11 = P1 + P4 - P5 + P7C12 = P3 + P5C21 = P2 + P4C22 = P1 - P2 + P3 + P6+P1 = S1 * S2P2 = S3 * B11P3 = A11 * S4P4 = A22 * S5P5 = S6 * B22P6 = S7 * S8P7  = S9*S10 
 +C11 = P1 + P4 - P5 + P7C12 = P3 + P5C21 = P2 + P4C22 = P1 - P2 + P3 + P6;
  
 the resulting DAG is sketched in the following figure: the resulting DAG is sketched in the following figure:
 {{:​ffnamespace:​strassen.png?​300|}} {{:​ffnamespace:​strassen.png?​300|}}
  
 +The DAG's instructions can be executed in parallel simply respecting data dependencies.
 ===== Some valid combinations of pipeline and farm (and feedback) ===== ===== Some valid combinations of pipeline and farm (and feedback) =====
  
 {{:​ffnamespace:​composition2.png?​400|}} {{:​ffnamespace:​composition2.png?​400|}}
ffnamespace/tutorial.1410947338.txt.gz · Last modified: 2014/09/17 11:48 by torquati