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
Next revision Both sides next revision
ffnamespace:tutorial [2014/09/25 15:44]
torquati [Tutorial]
ffnamespace:tutorial [2015/09/08 15:02]
torquati
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 = {      // the farm has 2 workers 
-    ​ff_pipe<fftask_t> pipe(new firstStage, secondStage, ​new ff_farm<>​(W)); +        make_unique<​thirdStage>​(),​ 
-    ​pipe.cleanup_nodes();+        make_unique<​thirdStage>​()  
 +    };  
 +    ​ff_Pipe<> pipe(make_unique<​firstStage>(), 
 +                   ​make_unique<​ff_node_F<​fftask_t>​ >(secondStage), 
 +                   ​make_unique<​ff_Farm<fftask_f> ​>(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;
ffnamespace/tutorial.txt · Last modified: 2015/09/08 16:52 by torquati