magistraleinformaticanetworking:spm:ffhwpipe
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| Prossima revisione | Revisione precedente | ||
| magistraleinformaticanetworking:spm:ffhwpipe [21/03/2012 alle 18:46 (14 anni fa)] – creata Marco Danelutto | magistraleinformaticanetworking:spm:ffhwpipe [21/03/2012 alle 18:53 (14 anni fa)] (versione attuale) – Marco Danelutto | ||
|---|---|---|---|
| Linea 1: | Linea 1: | ||
| ===== Sample pipeline applications in FastFlow ===== | ===== Sample pipeline applications in FastFlow ===== | ||
| + | The code appearing on this page is commented in the course notes PDF, Appendix A: FastFlow. | ||
| + | This is the code of a single concurrent activity printing an "Hello World" | ||
| + | <code c++ hello.cpp> | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | using namespace ff; | ||
| + | |||
| + | class Stage1: public ff_node { | ||
| + | public: | ||
| + | |||
| + | void * svc(void * task) { | ||
| + | std::cout << "Hello world" << std::endl; | ||
| + | return NULL; | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | int main(int argc, char * argv[]) { | ||
| + | | ||
| + | ff_pipeline pipe; | ||
| + | pipe.add_stage(new Stage1()); | ||
| + | |||
| + | ffTime(START_TIME); | ||
| + | if (pipe.run_and_wait_end()< | ||
| + | error(" | ||
| + | return -1; | ||
| + | } | ||
| + | ffTime(STOP_TIME); | ||
| + | |||
| + | std::cerr << "DONE, pipe time= " << pipe.ffTime() << " (ms)\n"; | ||
| + | std::cerr << "DONE, total time= " << ffTime(GET_TIME) << " (ms)\n"; | ||
| + | pipe.ffStats(std:: | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The second version following uses a two stage pipeline: the first stage prints " | ||
| + | <code c++ hello2stages.cpp> | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | using namespace ff; | ||
| + | |||
| + | class Stage1: public ff_node { | ||
| + | public: | ||
| + | |||
| + | void * svc(void * task) { | ||
| + | std::cout << "Hello " << std::endl; | ||
| + | char * p = (char *) calloc(sizeof(char), | ||
| + | strcpy(p," | ||
| + | sleep(1); | ||
| + | return ((void *)p); | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | class Stage2: public ff_node { | ||
| + | public: | ||
| + | |||
| + | void * svc(void * task) { | ||
| + | std::cout << ((char *)task) << std::endl; | ||
| + | free(task); | ||
| + | return GO_ON; | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | int main(int argc, char * argv[]) { | ||
| + | | ||
| + | ff_pipeline pipe; | ||
| + | pipe.add_stage(new Stage1()); | ||
| + | pipe.add_stage(new Stage2()); | ||
| + | |||
| + | if (pipe.run_and_wait_end()< | ||
| + | error(" | ||
| + | return -1; | ||
| + | } | ||
| + | | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | We add termination here: | ||
| + | <code c++ hello2terminate.cpp> | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | using namespace ff; | ||
| + | |||
| + | class Stage1: public ff_node { | ||
| + | public: | ||
| + | |||
| + | Stage1() { first = (1==1); } | ||
| + | |||
| + | void * svc(void * task) { | ||
| + | if(first) { | ||
| + | std::cout << "Hello " << std::endl; | ||
| + | char * p = (char *) calloc(sizeof(char), | ||
| + | strcpy(p," | ||
| + | sleep(1); | ||
| + | first = 0; | ||
| + | return ((void *)p); | ||
| + | } else { | ||
| + | return NULL; | ||
| + | } | ||
| + | } | ||
| + | private: | ||
| + | int first; | ||
| + | }; | ||
| + | |||
| + | class Stage2: public ff_node { | ||
| + | public: | ||
| + | |||
| + | void * svc(void * task) { | ||
| + | std::cout << ((char *)task) << std::endl; | ||
| + | free(task); | ||
| + | return GO_ON; | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | int main(int argc, char * argv[]) { | ||
| + | | ||
| + | ff_pipeline pipe; | ||
| + | pipe.add_stage(new Stage1()); | ||
| + | pipe.add_stage(new Stage2()); | ||
| + | |||
| + | if (pipe.run_and_wait_end()< | ||
| + | error(" | ||
| + | return -1; | ||
| + | } | ||
| + | | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
magistraleinformaticanetworking/spm/ffhwpipe.1332355616.txt.gz · Ultima modifica: 21/03/2012 alle 18:46 (14 anni fa) da Marco Danelutto
