#include #include #include #include #include #include using namespace ff; using namespace std; int N = 10; class Source: public ff_node { public: Source(unsigned int streamlen):streamlen(streamlen) {} void * svc(void * task) { if(streamlen != 0) { skepu::Vector * v = new skepu::Vector(N,(float)streamlen); streamlen--; task = (void *) v; #ifdef DEBUG std::cout << "Source delivering:" << *v << std::endl; #endif } else { task = NULL; } return task; } private: unsigned int streamlen; }; class Drain: public ff_node { void * svc(void * task) { skepu::Vector * v = (skepu::Vector *) task; #ifdef DEBUG std::cout << "Drain got " << *v << std::endl; #endif return(GO_ON); } }; #define ITERNO 800000 UNARY_FUNC(iters, float, a, for(int _i=0; _i * v = (skepu::Vector *) task; #ifdef DEBUG std::cout << "MapStage got: " << *v << std::endl; #endif skepu::Vector * r = new skepu::Vector(v->size()); skepu::Map skepumap(new iters); skepumap(*v, *r); #ifdef DEBUG std::cout << "MapStage delivering: " << *r << std::endl; #endif return((void *) r); } }; class SeqMapStage : public ff_node { private: int tasks; int wno; public: SeqMapStage(int wno):tasks(0),wno(wno) {} void svc_end() { cout << "CPU worker " << wno << " computed " << tasks << " tasks " << endl; } void * svc(void * task) { tasks++; skepu::Vector * v = (skepu::Vector *) task; skepu::Vector * r = new skepu::Vector(v->size()); for(int i=0; isize(); i++) (*r)[i] = f_iters((*v)[i]); return((void *) r); } }; class Emitter : public ff_node { void * svc (void * t) { return t; } }; class Collector : public ff_node { void * svc (void * t) { return t; } }; int main(int argc, char * argv[]) { if (argc==1) { std::cerr << "use: " << argv[0] << " streamlen veclen nw [skepuworkers]\n"; return -1; } int m = atoi(argv[1]); N = atoi(argv[2]); int nw = atoi(argv[3]); int skepuworker; if(argc>4) skepuworker=atoi(argv[4]); else skepuworker = 0; cout << "Using " << nw << " ff workers and " << skepuworker << " Skepu workers " << endl; // bild a 2-stage pipeline ff_pipeline pipe; pipe.add_stage(new Source(m)); // pipe.add_stage(new MapStage()); ff_farm<> farm; std::vector w; if(skepuworker!=0) for(int i=0; i