=====  Simple pipeline =====

=== Text ===
Write a four stage pipeline, such that:
  * first stages outputs a stream of integers from 1 to M (command line parameter)
  * the second stage increments integers by 1
  * the third stage squares the interegers
  * the fourth stage sums up all the integers received
The stream generator stage may be coded as:
<code c++>
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);
  }
};
</code>

=== Background ===
Pipeline API: 
<code>
#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
</code>

=== Solution ===
Sample solution [[simplefarmcode|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. 