treewalk.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <cilk/cilk.h>
  2. #include <cilk/reducer.h>
  3. #include <cilk/reducer_list.h>
  4. #include "monoid.hpp"
  5. typedef unsigned long int results_type[MAX_GENUS];
  6. void walk_children_stack(monoid m, results_type res,results_type resq);
  7. void walk_children_stack(monoid m, ind_t bound, results_type res,results_type resq);
  8. struct Results
  9. {
  10. results_type values;
  11. inline Results() {reset();};
  12. inline void reset() {for(int i=0; i<MAX_GENUS; i++) values[i] = 0;};
  13. };
  14. class ResultsReducer
  15. {
  16. struct Monoid: cilk::monoid_base<Results>
  17. {
  18. inline static void reduce (Results *left, Results *right){
  19. for(auto i=0; i<MAX_GENUS; i++) left->values[i] += right->values[i];
  20. }
  21. };
  22. private:
  23. cilk::reducer<Monoid> imp_;
  24. public:
  25. ResultsReducer() : imp_() {};
  26. inline unsigned long int & operator[](ind_t i) {
  27. return imp_.view().values[i];
  28. };
  29. inline results_type &get_array() {return imp_.view().values;}
  30. inline void reset() {imp_.view().reset();}
  31. };
  32. extern ResultsReducer cilk_results;
  33. extern ResultsReducer cilk_results_quotient;
  34. #ifdef TBB
  35. #include <tbb/scalable_allocator.h>
  36. extern cilk::reducer_list_append<monoid, tbb::scalable_allocator<monoid>> cilk_list_results;
  37. #else
  38. extern cilk::reducer_list_append<monoid> cilk_list_results;
  39. #endif
  40. void walk_children(const monoid m);
  41. void walk_children(const monoid &m, ind_t bound);
  42. void list_children(const monoid &m, ind_t bound);
  43. void treat(const monoid &m,results_type res,results_type res_quotient);
  44. void treat(const monoid &m,ResultsReducer& res,ResultsReducer& res_quotient);