Simple pipeline

Text

Write a four stage pipeline, such that:

The stream generator stage may be coded as:

class Iota : public ff_node {
private: 
  int m; 
public: 
  Iota(int m):m(m) {}
 
  void * svc(void * t) {
    for(int i=1; i<=m; i++) {
      int * n = new int(i); 
      ff_send_out((void *) n); 
    }
  return((void *)FF_EOS);
  }
};

Background

Pipeline API:

#include <ff/pipeline.hpp>

using namespace ff; 

  * ff_pipeline Pipe; // declaration
  * add_stage(ff_node *);  // adds  a stage
  * run_and_wait_end();   // runs the pipeline

compile with

  g++ -I directory/where/ff/has/been/placed filename.cpp -o execname -lpthread

Solution

Sample solution code.

Lesson goal

Show how much code is needed to implement and run a simple parallel application. Appreciate the amount of code needed to wrap existing code vs. the amount of code needed to declare the parallel structure of the application and to run the application.